Skip to content

UndoRedo

See the Undo and redo guide for examples and configuration details.

Options

undo

Can be set at: grid

Source code

undoRedo.undo : boolean | object

The undo option configures the UndoRedo plugin.

You can set the undo option to one of the following:

SettingDescription
trueEnable the UndoRedo plugin
falseDisable the UndoRedo plugin
{ maxHistory: <number> }Enable the plugin, and keep at most maxHistory steps on the undo stack

By default, the undo option is set to true, and the undo stack has no size limit. To disable the UndoRedo plugin completely, set the undo option to false. With false, nothing is recorded, so calling undo() through the API undoes nothing either.

With maxHistory, the oldest step is dropped once the stack grows past the limit. maxHistory takes a whole number from 0 up, or Infinity (no limit, the default); 0 keeps no steps. Lowering it with updateSettings() drops the oldest steps at once. Any other value is ignored with a warning, and the previous limit stays. The object form is available since 19.0.0.

Read more:

This option can only be set at the grid level. It has no effect when set in the columns, cells, or cell options.

Default: true
Example

// enable the `UndoRedo` plugin
undo: true,
// enable the `UndoRedo` plugin, and keep the last 100 steps
undo: {
maxHistory: 100,
},

Members

LICENSE

Source code

UndoRedo.LICENSE

Returns the license token of the plugin, its display name, where it is checked, and the tokens it requires.

PLUGIN_KEY

Source code

UndoRedo.PLUGIN_KEY

Returns the plugin key used to identify this plugin in Handsontable settings.

PLUGIN_PRIORITY

Source code

UndoRedo.PLUGIN_PRIORITY

Returns the priority order used to determine the order in which plugins are initialized.

SETTING_KEYS

Source code

UndoRedo.SETTING_KEYS

Returns whether the plugin handles its own settings keys without a dedicated key list.

Methods

clear

Source code

undoRedo.clear()

Clears undo and redo history.

destroy

Source code

undoRedo.destroy()

Destroys the plugin instance.

disablePlugin

Source code

undoRedo.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

done

Source code

undoRedo.done(wrappedAction, [source])

Stash information about performed actions.

Every change made through the grid’s API is recorded automatically. Use this method for a change the grid cannot see – for example, state your own code keeps outside the grid – by registering an action that knows how to reverse and replay itself.

Emits: Hooks#event:beforeUndoStackChange, Hooks#event:afterUndoStackChange, Hooks#event:beforeRedoStackChange, Hooks#event:afterRedoStackChange
Example

// Register a custom action for state kept outside the grid.
function setUnits(units) {
const undoRedo = hot.getPlugin('undoRedo');
const previousUnits = currentUnits;
undoRedo.done(() => ({
actionType: 'units',
undo(instance, callback) {
currentUnits = previousUnits;
instance.render();
callback();
},
redo(instance, callback) {
currentUnits = units;
instance.render();
callback();
},
}), 'units');
currentUnits = units;
hot.render();
}
ParamTypeDescription
wrappedActionfunctionThe action descriptor wrapped in a closure.
[source]stringoptional Source of the action. It is defined just for more general actions (not related to plugins).

enablePlugin

Source code

undoRedo.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

isEnabled

Source code

undoRedo.isEnabled() ⇒ boolean

Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit hook and if it returns true then the UndoRedo#enablePlugin method is called.

isRedoAvailable

Source code

undoRedo.isRedoAvailable() ⇒ boolean

Checks if redo action is available. It is not while an action that already changed the grid waits for an asynchronous validator: the grid then holds half of a step no recorded state describes.

Returns: boolean - Return true if redo can be performed, false otherwise.

isUndoAvailable

Source code

undoRedo.isUndoAvailable() ⇒ boolean

Checks if undo action is available. It is not while an action that already changed the grid waits for an asynchronous validator: the grid then holds half of a step no recorded state describes.

Returns: boolean - Return true if undo can be performed, false otherwise.

redo

Source code

undoRedo.redo()

Redo the previous action performed to the table (used to reverse an undo).

Emits: Hooks#event:beforeUndoStackChange, Hooks#event:afterUndoStackChange, Hooks#event:beforeRedoStackChange, Hooks#event:afterRedoStackChange, Hooks#event:beforeRedo, Hooks#event:afterRedo

undo

Source code

undoRedo.undo()

Undo the last action performed to the table.

Emits: Hooks#event:beforeUndoStackChange, Hooks#event:afterUndoStackChange, Hooks#event:beforeRedoStackChange, Hooks#event:afterRedoStackChange, Hooks#event:beforeUndo, Hooks#event:afterUndo

updatePlugin

Source code

undoRedo.updatePlugin([newSettings])

Applies a settings update. Runs for every updateSettings() call (SETTING_KEYS is true), so it must not disable and enable the plugin: disablePlugin() clears the history.

ParamTypeDescription
[newSettings]objectoptional The settings passed to updateSettings().