beforeAction
Description
Fires before an action is executed
Usage
beforeAction: (
action: string,
config: {
action?: string,
cell?: string,
row?: number,
col?: number,
val?: any,
prev?: any,
groupAction?: string,
pageId?: string | number,
pageName?: string,
// other properties of the action
} | object[]
) => void | boolean;
Parameters
The callback of the event takes the following parameters:
-
action- (required) the name of the action. Check the full list of available actions here -
config- (required) an object with parameters of the action. The set of properties depends on the action. The object can include:action- (optional) the name of the actioncell- (optional) the id of the cell or the range of cells the action is applied to, for example,"A1"or"B2:D5"row- (optional) the zero-based index of the row of the cellcol- (optional) the zero-based index of the column of the cellval- (optional) the new value that the action applies, for example, a cell value, a style or a sizeprev- (optional) the previous valuegroupAction- (optional) the name of the action that is executed instead ofactionwhencellis a range of cells, for example,"groupAction","groupRowAction"or"resizeCol"pageId- (optional) the id of the sheetpageName- (optional) the name of the sheet
When several actions are executed together, for example, on paste, the
actionparameter is"groupAction", andconfigis an array of such objects.
Returns
Return false to prevent an action from being executed; otherwise, return true
Example
const spreadsheet = new dhx.Spreadsheet("spreadsheet_container", {
// config parameters
});
spreadsheet.parse(dataset);
spreadsheet.events.on("beforeAction", (actionName, config) => {
if (actionName === "sortCells") {
console.log(actionName, config);
return false;
}
});
Changelog: Added in v4.3
Related articles: