Birch UI v0.1
Pricing

Undo and redo

Record cell edits, pastes and fills, undo them with Ctrl+Z, and keep your save handler in sync with undo and redo.

Open .md

With undoRedo on, the grid records every change that fires cellValueChanged: inline edits, setValue() calls, and paste and fill from Grid Pro. Undo is part of the MIT grid in @birchui/core.

orders-grid.ts
import { createGrid } from '@birchui/core';

const grid = createGrid<Order>(el, {
  columns,
  rows: orders,
  getRowId: (order) => order.id,
  undoRedo: { limit: 50 },
});

undoRedo: true keeps the last 100 steps. { limit } sets another positive whole number; an invalid limit logs one warning and falls back to 100. Setting undoRedo to false with update() clears the history.

UndoRedoOptionsinterface@birchui/coreFull reference
PropertyTypeDescription
limitoptionalnumber—

Keys and methods#

Keys (Windows, Linux) macOS Action
Ctrl+Z ⌘+Z Undo
Ctrl+Y or Ctrl+Shift+Z ⌘+Shift+Z Redo

The keys work while the grid has focus and no cell is being edited; inside an editor they belong to the text box. After undo or redo, focus moves to the restored cell.

GridApiinterface@birchui/coreFull reference
MemberTypeDescription
undo()() => boolean—
redo()() => boolean—
canUndo()() => boolean—
canRedo()() => boolean—
clearHistory()() => void—
TypeScript
undoButton.addEventListener('click', () => grid.undo());
redoButton.addEventListener('click', () => grid.redo());

grid.on('cellValueChanged', () => {
  undoButton.disabled = !grid.canUndo();
  redoButton.disabled = !grid.canRedo();
});

Steps#

Writes made in the same task form one step. Pasting a 10 by 4 range, dragging the fill handle, or a listener that writes three cells in one go are each undone at once.

Saving changes#

Undo and redo write through setValue(), so cellValueChanged fires with source: 'undo' or source: 'redo'. A save handler written for edits keeps working:

TypeScript
grid.on('cellValueChanged', ({ row, colId, newValue, source }) => {
  void api.patchOrder(row.id, { [colId]: newValue }, { reason: source });
});

Writes made by undo and redo, and writes your listeners make in response to them, are not recorded again.

Limits#

  • Rows are matched by getRowId. Give the grid one; changes to rows that have since been removed are skipped.
  • setRows() keeps the history. Call clearHistory() when you load a different dataset, or after a successful save if users should not undo past it.
  • Only cell values are recorded. Sorting, filtering, column moves and row transactions are not undoable; use saved state for view changes.

↑ ↓ to move, Enter to open, Esc to close