Skip to content

ContextMenu

Options

contextMenu

Source code

contextMenu.contextMenu : boolean | Array<string> | object

The contextMenu option configures the ContextMenu plugin.

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

SettingDescription
falseDisable the ContextMenu plugin
true- Enable the ContextMenu plugin
- Use the default context menu options
An array- Enable the ContextMenu plugin
- Modify individual context menu options
An object- Enable the ContextMenu plugin
- Apply a custom context menu configuration

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 `ContextMenu` plugin
// use the default context menu options
contextMenu: true,
// enable the `ContextMenu` plugin
// and modify individual context menu options
contextMenu: ['row_above', 'row_below', '---------', 'undo', 'redo'],
// enable the `ContextMenu` plugin
// and apply a custom context menu configuration
contextMenu: {
items: {
'option1': {
name: 'Option 1'
},
'option2': {
name: 'Option 2',
submenu: {
items: [
{
key: 'option2:suboption1',
name: 'Suboption 1',
callback: function(key, options) {
...
}
},
...
]
}
}
}
},

Members

DEFAULT_ITEMS

Source code

ContextMenu.DEFAULT_ITEMS ⇒ Array<string>

Context menu default items order when contextMenu options is set as true.

PLUGIN_DEPS

Source code

ContextMenu.PLUGIN_DEPS

Returns the list of plugin dependencies required before this plugin can be initialized.

PLUGIN_KEY

Source code

ContextMenu.PLUGIN_KEY

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

PLUGIN_PRIORITY

Source code

ContextMenu.PLUGIN_PRIORITY

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

SEPARATOR

Source code

ContextMenu.SEPARATOR ⇒ MenuItemConfig

The item descriptor that identifies a menu separator. Use it as a value in a custom items configuration object to insert a separator line at that key.

Methods

close

Source code

contextMenu.close()

Closes the menu.

destroy

Source code

contextMenu.destroy()

Destroys the plugin instance.

disablePlugin

Source code

contextMenu.disablePlugin()

Disables the plugin functionality for this Handsontable instance.

enablePlugin

Source code

contextMenu.enablePlugin()

Enables the plugin functionality for this Handsontable instance.

executeCommand

Source code

contextMenu.executeCommand(commandName, …params)

Execute context menu command.

The executeCommand() method works only for selected cells.

When no cells are selected, executeCommand() doesn’t do anything.

You can execute all predefined commands:

  • 'row_above' - Insert row above
  • 'row_below' - Insert row below
  • 'col_left' - Insert column left
  • 'col_right' - Insert column right
  • 'clear_column' - Clear selected column
  • 'remove_row' - Remove row
  • 'remove_col' - Remove column
  • 'undo' - Undo last action
  • 'redo' - Redo last action
  • 'make_read_only' - Make cell read only
  • 'alignment:left' - Alignment to the left
  • 'alignment:top' - Alignment to the top
  • 'alignment:right' - Alignment to the right
  • 'alignment:bottom' - Alignment to the bottom
  • 'alignment:middle' - Alignment to the middle
  • 'alignment:center' - Alignment to the center (justify).

Or you can execute command registered in settings where key is your command name.

ParamTypeDescription
commandNamestringThe command name to be executed.
…params*Additional parameters passed to command executor module.

isEnabled

Source code

contextMenu.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 ContextMenu#enablePlugin method is called.

open

Source code

contextMenu.open(position, offset)

Opens the menu and positions it based on the passed coordinates.

Emits: Hooks#event:beforeContextMenuShow, Hooks#event:afterContextMenuShow
Example

const menu = hot.getPlugin('contextMenu');
hot.selectCell(0, 0);
menu.open({ top: 50, left: 50 });
ParamTypeDescription
positionObject
Event
An object with top and left properties (coordinates relative to the browser viewport, without scroll offsets), or a native browser Event instance (e.g., a MouseEvent).
offsetObjectAn object that applies an offset to the menu position.

updatePlugin

Source code

contextMenu.updatePlugin()

Updates the plugin’s state.

This method is executed when updateSettings() is invoked with any of the following configuration options: