Skip to main content

add()

pro version only

This functionality requires PRO version of the DHTMLX Grid (or DHTMLX Suite) package.

adds a new action into the history of actions within the Grid

Usage

type ActionType = "add" | "remove" | "removeAll" | "change";

interface IAction {
type: ActionType;
batch: IRow[];
inverse?: IAction;
}

add(action: IAction): void;

Parameters:

action(object) the action object that contains the following properties:
  • type - (string) the type of action: "add", "remove", "removeAll", or "change"
  • batch - (array) an array of rows representing the data affected by the action (e.g., added, removed, or modified rows)
  • inverse - (object) optional, the inverse action required for undoing (mandatory for the "change" and "removeAll" types, not required for other types)
note

The action argument must conform to the IAction interface. If the module is disabled, the action type is invalid, or the inverse property is missing (for actions with the "change" and "removeAll" types), the error event is triggered.

Example

// The example shows adding a new row via `DataCollection` 
const grid = new dhx.Grid("grid_container", {
columns: [
{ id: "name", header: [{ text: "Name" }] },
{ id: "value", header: [{ text: "Value" }] },
],
data: [
{ id: "1", name: "Item 1", value: 10 },
],
history: true
});

// adding a new row via DataCollection
const newItem = { id: "2", name: "New Item", value: 20 };
grid.data.add(newItem);

// recording the action in the history
grid.history.add({
type: "add",
batch: [{ ...newItem }],
});

// checking the history
const history = grid.history.getHistory();
console.log(history.length); // ->1

Change log:

added in v9.2