ReoGrid ReoGrid Web

Undo / Redo

ReoGrid Web tracks edit history and supports undo/redo through keyboard shortcuts and a programmatic API.


Keyboard shortcuts

ShortcutOperation
Ctrl+Z / ⌘+ZUndo
Ctrl+Y / ⌘+YRedo — or, with nothing to redo, repeat the last action
F4Same as Ctrl+Y
Ctrl+Shift+Z / ⌘+Shift+ZRedo only

While a cell is being edited, Ctrl+Z, Ctrl+Y and Ctrl+Shift+Z undo and redo the text of that edit only — a typing run, a deletion, a paste and an IME conversion are one step each — back to the text the editor opened with. Once the edit is committed, Ctrl+Z undoes it as one step. (Before v1.7.2 the editor kept the browser’s own history, so Ctrl+Z in one cell could bring back text deleted in another.)


Repeating the last action (F4 / Ctrl+Y)

Since v1.7.2, as in Excel, F4 (or Ctrl+Y / ⌘+Y, which does exactly the same) does the last action again on whatever is selected now — make one cell bold, select another range, press F4. A Ctrl+click selection of several ranges gets it on every range, and the repeat is an ordinary step that Ctrl+Z undoes. Available in both editions.

  • What follows the new selection is the operation, not the old shape: an outside border outlines the new range, an inserted row count is the number of rows now selected, a paste lands on the selection’s top-left cell.
  • Right after an undo, F4 / Ctrl+Y redo; they repeat only once there is nothing left to redo. Ctrl+Shift+Z never repeats.
  • Only the newest action counts. If it cannot be repeated, F4 does nothing.
RepeatsDoes not repeat
Style, number format, bordersTyping a value into a cell
Merge / unmergeAuto-fill
Column width, row heightMoving cells, rows or columns by dragging
Insert / delete rows and columnsSort, replace
Hide / show rows and columnsImage and page-break edits
Group / ungroup rows and columnsCut & paste
Clear (Delete), paste

From code:

actionManager.canRepeat();        // boolean — something to redo or repeat
actionManager.repeatLastAction(); // on the current selection

// or on a range of your choice
actionManager.repeatLastAction({
  ranges: [{ topRow: 4, leftColumn: 1, bottomRow: 8, rightColumn: 3 }],
});

repeatLastAction() returns true when something was redone or repeated.

An ActionGroup repeats when it is one operation spread over cells or ranges (every child of the same class with the same settings — what createSetRangeStyleAction() builds). To make your own action repeatable, implement repeat(target) and return a new action for target.ranges (never this — it holds the undo state of the run already on the stack; return null when the operation is not possible there). Add repeatKey() — the settings without the location — if it should also repeat from inside a group.


ActionManager API

Control undo/redo programmatically through the ActionManager.

const { actionManager } = grid;

// Undo
actionManager.undo();

// Redo
actionManager.redo();

// Check state
actionManager.canUndo(); // boolean
actionManager.canRedo(); // boolean

// Clear history
actionManager.clear();

Monitoring undo/redo state

actionManager.onUndoRedoChange(() => {
  console.log('canUndo:', actionManager.canUndo());
  console.log('canRedo:', actionManager.canRedo());
});

Cell operations via Actions

When operations are executed through the ActionManager, they automatically support undo/redo.

Since v1.7.1 @reogrid/lite exports the actions for the features Lite has — cell values, styles, column widths and row heights, merges, borders, number formats, auto-fill, paste, clear and replace — along with ActionManager and ActionGroup. The examples below import from @reogrid/pro; with Lite, import the same names from @reogrid/lite. The insert/delete, hide, sort and grouping actions are Pro only.

Changing cell values

import { SetCellInputAction } from '@reogrid/pro';

actionManager.execute(
  new SetCellInputAction(0, 0, 'Hello')
);

Changing cell styles

import { SetCellStyleAction, createSetRangeStyleAction } from '@reogrid/pro';

// Single cell
actionManager.execute(
  new SetCellStyleAction(0, 0, { bold: true })
);

// Range — the factory takes a name and an explicit cell list
const cells: Array<{ row: number; column: number }> = [];
for (let row = 0; row <= 4; row++) {
  for (let column = 0; column <= 3; column++) {
    cells.push({ row, column });
  }
}

actionManager.execute(
  createSetRangeStyleAction('Set range style', cells, { backgroundColor: '#dbeafe' })
);

Changing column widths / row heights

import { SetColumnWidthAction, SetRowHeightAction } from '@reogrid/pro';

actionManager.execute(new SetColumnWidthAction(0, 200));
actionManager.execute(new SetRowHeightAction(0, 40));

Cell merging

import { MergeCellsAction, UnmergeCellsAction } from '@reogrid/pro';

actionManager.execute(new MergeCellsAction(0, 0, 0, 4));
actionManager.execute(new UnmergeCellsAction(0, 0, 0, 4));

Borders

import { SetRangeBorderAction } from '@reogrid/pro';

actionManager.execute(
  new SetRangeBorderAction(0, 0, 4, 3, {
    style: 'solid',
    color: '#000',
  })
);

Inserting / deleting rows and columns

import {
  InsertRowsAction, DeleteRowsAction,
  InsertColumnsAction, DeleteColumnsAction,
} from '@reogrid/pro';

actionManager.execute(new InsertRowsAction(2, 3));
actionManager.execute(new DeleteRowsAction(2, 3));
actionManager.execute(new InsertColumnsAction(1, 2));
actionManager.execute(new DeleteColumnsAction(1, 2));

Showing / hiding rows and columns

import { SetRowHiddenAction, SetColumnHiddenAction } from '@reogrid/pro';

actionManager.execute(new SetRowHiddenAction([2, 3], true));
actionManager.execute(new SetColumnHiddenAction([1], false));

Sorting

import { SortColumnAction } from '@reogrid/pro';

actionManager.execute(new SortColumnAction({ column: 0, order: 'asc' }));

Grouping

import {
  GroupRowsAction, UngroupRowsAction,
  GroupColumnsAction, UngroupColumnsAction,
} from '@reogrid/pro';

actionManager.execute(new GroupRowsAction(1, 4));
actionManager.execute(new UngroupRowsAction(1, 4));

Paste and clear

import { PasteAction, ClearRangeAction } from '@reogrid/pro';

actionManager.execute(new ClearRangeAction(0, 0, 4, 3));

Available Actions

ActionDescription
SetCellInputActionChange cell value
SetCellStyleActionChange cell style
createSetRangeStyleAction()Change range style
SetColumnWidthActionChange column width
SetRowHeightActionChange row height
SetRangeBorderActionChange range border
SetCellNumberFormatActionChange number format
MergeCellsActionMerge cells
UnmergeCellsActionUnmerge cells
InsertRowsActionInsert rows
DeleteRowsActionDelete rows
InsertColumnsActionInsert columns
DeleteColumnsActionDelete columns
SetRowHiddenActionShow/hide rows
SetColumnHiddenActionShow/hide columns
SortColumnActionSort column
GroupRowsActionGroup rows
UngroupRowsActionUngroup rows
GroupColumnsActionGroup columns
UngroupColumnsActionUngroup columns
ToggleOutlineActionToggle outline collapse/expand
CollapseToLevelActionCollapse to level
PasteActionPaste
ClearRangeActionClear range

Protected cell checking

actionManager.execute() automatically checks cell protection. Changes to protected cells are rejected and false is returned.

const success = actionManager.execute(
  new SetCellInputAction(0, 0, 'new value')
);
if (!success) {
  console.log('Operation blocked by cell protection');
}

Undo capacity

By default, up to 30 undo steps are retained. This can be changed with the undoCapacity option in createReogrid().

const grid = createReogrid({
  workspace: '#grid',
  undoCapacity: 100,
});
Stay Updated

Be first to know — get updates as they ship

Get notified of new releases, features, and announcements.
No spam — just updates that matter.