Methods - nandaabiz/jquery-handsontable-old-0.10 GitHub Wiki
NOTICE: This document can be out of date. Since Handsontable 0.15.0 documentation was moved to docs.handsontable.com.
After Handsontable is constructed, you can modify the grid behavior using the available public methods.
These are 2 equal ways to call a Handsontable method:
//all following examples assume that you constructed Handsontable like this
var exampleContainer1 = document.getElementById('example1');
var ht = new Handsontable(exampleContainer1, options);
//now, to use setDataAtCell method, you can call method on the instance returned by the constructor (RECOMMENDED)
ht.setDataAtCell(0, 0, 'new value');Alternatively, you can call the method using jQuery wrapper (obsolete, requires initialization using our jQuery guide
$('#example1').handsontable('setDataAtCell', 0, 0, 'new value');This is the list of available public methods, grouped by their functionality:
- updateSettings (
options: Object) - Use it if you need to change configuration after initialization
- getSettings ()
- Returns an object containing the current grid settings
- loadData (
data: Array) - Reset all cells in the grid to contain data from the
dataarray - listen ()
- Listen to keyboard input on document body
version added: 0.11 - getCellRenderer (
row: Number,col: Number) - Returns renderer type
version added: 0.11 - unlisten ()
- Stop listening to keyboard input on document body
version added: 0.11 - isListening ()
- Returns
trueif current Handsontable instance is listening to keyboard input on document body
version added: 0.11 - render ()
- Rerender the table
- destroy ()
- Remove grid from DOM
- validateCells (
callback: Function) - Validates all cells using their validator functions and calls callback when finished. Does not render the view.
- getData ()
getData (row: Number,col: Number,row2: Number,col2: Number) - Return the current data object (the same that was passed by
dataconfiguration option orloadDatamethod). Optionally you can provide cell rangerow,col,row2,col2to get only a fragment of grid data - getDataAtCell (
row: Number,col: Number) - Return cell value at
row,col.rowandcolare the visible indexes (note that if columns were reordered or sorted, the current order will be used) - getDataAtRowProp (
row: Number,prop: String) - Same as above, except instead of
col, you provide name of the object property (e.g.'first.name') - getDataAtRow (
row: Number) - Returns a single row of the data (array or object, depending on what you have).
rowis the visible index of the row
version added: 0.9-beta2 - getSourceDataAtRow (
row: Number) - Returns a single row of the data (array or object, depending on what you have).
rowis the index of the row in the data source
version added: 0.11.0-beta3 - getDataAtCol (
col: Number) - Returns array of column values from the data source.
colis the visible index of the column
version added: 0.9-beta2 - getSourceDataAtCol (
col: Number) - Returns array of column values from the data source.
colis the index of the row in the data source
version added: 0.11.0-beta3 - getDataAtProp (
prop: String) - Given the object property name (e.g.
'first.name'), returns array of column values from the data source.
version added: 0.9-beta2 - getCopyableData (
startRow: Number,startCol: Number,endRow: Number,endCol: Number) - Get value of selected range. Each column is separated by tab, each row is separated by new line character
version added: 0.11
<dt>getValue ()</dt>
<dd>Returns value of selected cell
<br><small>version added: 0.11</small>
</dd>
- setDataAtCell (
row: Number,col: Number,value: Mixed,source: String (Optional))
setDataAtCell (changes: Array,source: String (Optional)) - Set new value to a cell. To change many cells at once, pass an array of
changesin format[ [row, col, value], ... ]as the only parameter.colis the index of visible column (note that if columns were reordered, the current order will be used).sourceis a flag for before/afterChange events. If you pass only array of changes thensourcecould be set as second parameter. - setDataAtRowProp (
row: Number,prop: String,value: Mixed,source: String (Optional))
setDataAtRowProp (changes: Array,source: String (Optional)) - Same as above, except instead of
col, you provide name of the object property (e.g.[0, 'first.name', 'Jennifer']). - populateFromArray (
row: Number,col: Number,input: Array,endRow: Number,endCol: Number,source: String (Optional),populateMethod: String (Optional)) - Populate cells at position with 2D
inputarray (e.g.[ [1, 2], [3, 4] ]).
UseendRow,endColwhen you want to cut input when certain row is reached.
Optionalsourceparameter (default value "populateFromArray") is used to identify this call in the resulting events (beforeChange, afterChange).
OptionalpopulateMethodparameter (default value "overwrite", possible values "shift_down" and "shift_right") has the same effect as pasteMethod option (see Options page)
version added: 0.9.0 - spliceCol (
col: Number,index: Number,amount: Number,element1: Mixed, ...,elementN: Mixed) - Adds/removes data from the column. This function works is modelled after Array.splice. Parameter
colis the index of column in which do you want to do splice. Parameterindexis the row index at which to start changing the array. If negative, will begin that many elements from the end. Parameteramount, is the number of old array elements to remove. If the amount is 0, no elements are removed. Fourth and further parameters are theelementsto add to the array. If you don't specify any elements, spliceCol simply removes elements from the array.
version added: 0.9-beta2 - spliceRow (
row: Number,index: Number,amount: Number,element1: Mixed, ...,elementN: Mixed) - Adds/removes data from the row. This function works is modelled after Array.splice. Parameter
rowis the index of row in which do you want to do splice. Parameterindexis the column index at which to start changing the array. If negative, will begin that many elements from the end. Parameteramount, is the number of old array elements to remove. If the amount is 0, no elements are removed. Fourth and further parameters are theelementsto add to the array. If you don't specify any elements, spliceCol simply removes elements from the array.
version added: 0.11
- alter (
'insert_row',index: Number,amount: Number (Optional),source: String (Optional)) - Insert new row(s) above the row at given
index. If index isnullorundefined, the new row will be added after the current last row. Defaultamountequals 1 - alter (
'insert_col',index: Number,amount: Number (Optional),source: String (Optional)) - Insert new column(s) before the column at given
index. If index isnullorundefined, the new column will be added after the current last column. Defaultamountequals 1 - alter (
'remove_row',index: Number,amount: Number (Optional),source: String (Optional)) - Remove the row(s) at given
index. Defaultamountequals 1 - alter (
'remove_col',index: Number,amount: Number (Optional),source: String (Optional)) - Remove the column(s) at given
index. Defaultamountequals 1
- getCell (
row: Number,col: Number,topmost: Boolean) -
Returns TD element for given
row,colif it is rendered on screen.
Returnsnullif the TD is not rendered on screen (probably because that part of table is not visible).
If thetopmostparameter istrue, returns the topmost cell from all overlays (such as fixed rows/columns). - getCellMeta (
row: Number,col: Number) - Return cell properties for given
row,colcoordinates - setCellMeta (
row: Number,col: Number,key: String,val: String) - Sets cell meta data object
keycorresponding to paramsrow,col
version added: 0.11 - destroyEditor (
revertOriginal: Boolean (Optional)) - Destroys current editor, renders and selects current cell. If revertOriginal == false, edited data is saved. Otherwise previous value is restored
- selectCell (
row: Number,col: Number,row2: Number,col2: Number,scrollToSelection: Boolean (Optional)) - Select cell
row,color range finishing atrow2,col2. By default, viewport will be scrolled to selection - deselectCell ()
- Deselect current selection
- getSelected ()
- Return index of the currently selected cells as an array
[startRow, startCol, endRow, endCol]. Start row and start col are the coordinates of the active cell (where the selection was started). - getSelectedRange ()
- Returns current selection as a WalkontableCellRange object. Returns undefined if there is no selection.
version added: 0.11 - clear ()
- Clears grid
version added: 0.11
- countRows ()
- Returns total number of rows in the grid
- countCols ()
- Returns total number of columns in the grid
- colToProp (
column: Number) - Returns property name that corresponds with the given column index
- rowOffset ()
- Returns index of first visible row
- colOffset ()
- Returns index of first visible column
- countVisibleRows ()
- Returns number of visible rows
- countVisibleCols ()
- Returns number of visible columns
- countEmptyRows (
ending: Boolean (Optional)) - Returns number of empty rows. If the optional
endingparameter is true, returns number of empty rows at the bottom of the table - countEmptyCols (
ending: Boolean (Optional)) - Returns number of empty columns. If the optional
endingparameter is true, returns number of empty columns at right hand edge of the table - isEmptyRow (
row: Number) - Returns true if the row at the given index is empty, false otherwise
- isEmptyCol (
col: Number) - Returns true if the column at the given index is empty, false otherwise
- getRowHeader (
row: Number) - Returns array of row headers (if they are enabled). If param
rowgiven, return header at given row as string - getColHeader (
col: Number) - Returns array of col headers (if they are enabled). If param
colgiven, return header at given col as string - hasRowHeaders ()
- Returns information of this table is configured to display row headers
version added: 0.11 - hasColHeaders ()
- Returns information of this table is configured to display column headers
version added: 0.11 - getColWidth (
col: Number) - Return column width
version added: 0.11 - getRowHeight (
row: Number) - Return row height
version added: 0.11 - propToCol (
property: String) - Returns column index that corresponds with the given property
- clearUndo ()
- Clear undo history
- isUndoAvailable ()
- Return true if undo can be performed, false otherwise
- isRedoAvailable ()
- Return true if redo can be performed, false otherwise
- undo ()
- Undo last edit
- redo ()
- Redo edit (used to reverse an undo)
- sort (
column: Number,order: Boolean) - Sorts table content by cell values in given
column, usingorder.columnis a zero-based column index. Order of sorting can be either ascending (order=true) or descending (order=false).Note I: This method is only available when
columnSortingplugin is enabled. See column sorting demo for details.Note II: Running this method will not alter the table data. Sorting takes place only in view layer.