Tutorial: Using callbacks

Using callbacks

Callbacks

This page shows usage of some callbacks available in Handsontable. If you require a new callback to be added, please open an issue. Note that some callbacks are checked on this page by default.

Choose events to be logged:

Definition for source argument

It's worth to mention that some of the hooks are triggered from the inside of the Handsontable (Core) and some from the plugins. In some situations it is helpful to know what triggered the callback (if it was done by Handsontable itself, triggered from external code or a user action). That's why in crucial hooks Handsontable delivers source as an argument which informs you about who've triggered the action. Thanks to source you can create additional conditions based on that information.

source argument is optional. It takes following values:

  • auto - Action triggered by Handsontable and reason for it is releated directly with settings aplied to Handsontable. For instance afterCreateRow will be fired with this when minSpareRows will be greater then 0;
  • edit - Action triggered by Handsontable after the data has been changed (for example after an edit or using setData* methods);
  • loadData - Action triggered by Handsontable after the loadData or updateSettings({data: myData})(with data property) method has been called;
  • populateFromArray - Action triggered by Handsontable after requesting for populating data;
  • spliceCol - Action triggered by Handsontable after the column data splicing has been done;
  • spliceRow - Action triggered by Handsontable after the row data splicing has been done;
  • timeValidate - Action triggered by Handsontable after the time validator has been called (for example after an edit);
  • dateValidate - Action triggered by Handsontable after the date validator has been called (for example after an edit);
  • validateCells - Action triggered by Handsontable after the validation process has been triggered;
  • Autofill.fill - Action triggered by the AutoFill plugin;
  • Autofill.fill - Action triggered by the AutoFill plugin;
  • ContextMenu.clearColumns - Action triggered by the ContextMenu plugin after the "Clear column" has been clicked;
  • ContextMenu.columnLeft - Action triggered by the ContextMenu plugin after the "Insert column on the left" has been clicked;
  • ContextMenu.columnRight - Action triggered by the ContextMenu plugin after the "Insert column on the right" has been clicked;
  • ContextMenu.removeColumn - Action triggered by the ContextMenu plugin after the "Remove column" has been clicked;
  • ContextMenu.removeRow - Action triggered by the ContextMenu plugin after the "Remove Row" has been clicked;
  • ContextMenu.rowAbove - Action triggered by the ContextMenu plugin after the "Insert row above" has been clicked;
  • ContextMenu.rowBelow - Action triggered by the ContextMenu plugin after the "Insert row below" has been clicked;
  • CopyPaste.paste - Action triggered by the CopyPaste plugin after the value has been pasted;
  • ObserveChanges.change - Action triggered by the ObserveChanges plugin after the changes has been detected;
  • UndoRedo.redo - Action triggered by the UndoRedo plugin after the change has been redone;
  • UndoRedo.undo - Action triggered by the UndoRedo plugin after the change has been undone;
  • GantChart.loadData - Action triggered by the GantChart plugin after the data has been loaded;
  • ColumnSummary.set - Action triggered by the ColumnSummary plugin after the calculation has been done;
  • ColumnSummary.reset - Action triggered by the ColumnSummary plugin after the calculation has been reset.

List of callback that operates on source parameter:

beforeKeyDown use case

The following demo uses beforeKeyDown callback to modify some key bindings:

  • Pressing DELETE or BACKSPACE on a cell deletes the cell and shifts all cells beneath it in the column up resulting in the cursor (which doesn't move) having the value previously beneath it, now in the current cell.
  • Pressing ENTER in a cell (not changing the value) results in pushing all the cells in the column beneath this cell down one row (including current cell) resulting in a blank cell under the cursor (which hasn't moved).

Help us improve this page