Lattice Grid Buy a licence

developer guide

Undo and Redo in a JavaScript Data Grid

Undo covers the grid rather than the last cell: an edit, a fill, a pasted block or a row move all step back the way a reader expects, and forward again.

Developer guidePresenting and saved views › Undo and Redo in a JavaScript Data Grid

Undo

Undo covers the whole grid, not only edits. Sorts, filters, column moves, grouping, an applied view and a restore all record an entry, and each carries a label written for a button.

Naming the action

grid.history.peek('undo');   // { type: 'sort', label: 'sort by Region' }
grid.history.undo();
grid.history.list();         // the timeline, newest first

A button that says only "Undo" makes the user press it to find out what it does: and pressing it is the thing they were unsure about. "Undo sort by Region" is decided before the click rather than after.

Grouping is by user action, not by internal operation. A multi-cell paste is one entry, not one per cell. An AI plan is one entry however many actions it contains.

Grouping your own changes

grid.history.transaction('apply the quarterly template', () => {
  grid.sort.set([{ col: 'margin', dir: 'desc' }]);
  grid.filters.set({ col: 'region', op: 'eq', value: 'EMEA' });
  grid.columns.hide(['notes', 'mgmtIp']);
});
// one press of undo reverses all three