Skip to content

Handsontable module events

The Handsontable module comes with an event system where you can add functions that will be called when something happens on the grid. To setup a new hook on an event, you have to call Handsontable.on() with the unique id of your table, the event and your callback function. Additional parameters are in a list passed as the first argument to the function. Here is an example:

Handsontable.on('main', 'onDidChangeSelection', function(selection){
    if(is.null(selection)){
        cat("Selection: nothing is selected!\n")
    }
    else {
        cat(paste0("Selection: from (",selection[[1L]],",",selection[[2L]],") to (",selection[[3L]],",",selection[[4L]],")!\n"))
    }
});

You can also use a previously created function:

myCallback <- function(selection){
    if(is.null(selection)){
        cat("Selection: nothing is selected!\n")
    }
    else {
        cat(paste0("Selection: from (",selection[[1L]],",",selection[[2L]],") to (",selection[[3L]],",",selection[[4L]],")!\n"))
    }
}

Handsontable.on('main', 'onDidChangeSelection', myCallback);

onDidChangeSelection

Called when the user changed the current selection in the table. The callback only have one parameter, selection, which is NULL if nothing is selected. Otherwise, it's a vector of 4 values:

  • The first value is the index of the starting row;
  • The second value is the index of the starting column;
  • The third value is the index of the ending row;
  • The last value is the index of the ending column.

onDidChangeValue

Called when the user changes the value of the table. The callback must have 3 parameters:

  • columns: the column names;
  • rows: the row names;
  • value: the data frame.

onDidLoad

onDidLoad is called when the grid finished its initialization, and is ready to be updated or modified. There is no argument to onDidLoad.