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:
|
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
Related article: Adding/removing Grid history actions
Related API: remove()
, removeAll()
, getHistory()
Change log:
added in v9.2