Skip to content

UndoRedo

Description

Initializes the plugin and registers all built-in undo/redo action handlers for the given Handsontable instance.

Options

undo

Source code

undoRedo.undo : boolean

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

By default, the undo option is set to true, To disable the UndoRedo plugin completely, set the undo option to false.

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: undefined
Example

// enable the `UndoRedo` plugin
undo: true,

Members

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.

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

// Register a custom action, for example when setting cell metadata directly
// (a change that UndoRedo doesn't track by default).
function setCellBackgroundColor(row, col, className) {
const undoRedo = hot.getPlugin('undoRedo');
const previousClassName = hot.getCellMeta(row, col).className;
undoRedo.done(() => ({
actionType: 'cellBackgroundColor',
undo(instance, callback) {
instance.setCellMeta(row, col, 'className', previousClassName);
instance.render();
callback();
},
redo(instance, callback) {
instance.setCellMeta(row, col, 'className', className);
instance.render();
callback();
},
}), 'cellBackgroundColor');
hot.setCellMeta(row, col, 'className', className);
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.

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

isUndoAvailable

Source code

undoRedo.isUndoAvailable() ⇒ boolean

Checks if undo action is available.

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