Skip to main content

getHistory()

pro version only

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

returns a copy of the array of all actions in the Grid history to prevent accidental modification of the internal structure

Usage

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

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

getHistory(): IAction[];

Returns:

Returns a copy of the array of all actions in the Grid history, where each action presents an object described below:

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 (for the "change" and "removeAll" types)

Example

// The example shows retrieving the history
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 actions
grid.history.add({
type: "change",
batch: [{ id: "1", name: "Updated Item", value: 15 }],
inverse: { type: "change", batch: [{ id: "1", name: "Item 1", value: 10 }] },
});
grid.history.add({
type: "add",
batch: [{ id: "2", name: "New Item", value: 20 }],
});

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

Change log:

added in v9.2