Skip to content

Latest commit

 

History

History
75 lines (59 loc) · 2.49 KB

spreadsheet_beforeaction_event.md

File metadata and controls

75 lines (59 loc) · 2.49 KB
sidebar_label beforeAction
title beforeAction event
description Intercept actions in DHTMLX Spreadsheet with the beforeAction event, which receives the name and parameters of an action and cancels it when the handler returns false.

beforeAction

Description

@short: 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 action
    • cell - (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 cell
    • col - (optional) the zero-based index of the column of the cell
    • val - (optional) the new value that the action applies, for example, a cell value, a style or a size
    • prev - (optional) the previous value
    • groupAction - (optional) the name of the action that is executed instead of action when cell is a range of cells, for example, "groupAction", "groupRowAction" or "resizeCol"
    • pageId - (optional) the id of the sheet
    • pageName - (optional) the name of the sheet

    When several actions are executed together, for example, on paste, the action parameter is "groupAction", and config is 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: