Skip to content

ContextMenuPlugin

Context Menu Plugin for tbw-grid

Adds a customizable right-click menu to grid cells. Build anything from simple copy/paste actions to complex nested menus with conditional visibility, icons, and keyboard shortcuts.

import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';
PropertyTypeDescription
idstringUnique item identifier
namestringDisplay label
iconstringIcon class or HTML
shortcutstringKeyboard shortcut hint
action(params) => voidClick handler
disabledboolean | (params) => booleanDisable condition
visibleboolean | (params) => booleanVisibility condition
itemsMenuItem[]Submenu items
separatorbooleanCreate a divider line
PropertyTypeDescription
rowIndexnumberClicked row index
colIndexnumberClicked column index
fieldstringColumn field name
valueanyCell value
rowanyFull row data
columnColumnConfigColumn configuration
PropertyDefaultDescription
--tbw-context-menu-bgvar(--tbw-color-panel-bg)Menu background
--tbw-context-menu-fgvar(--tbw-color-fg)Menu text color
--tbw-context-menu-hovervar(--tbw-color-row-hover)Item hover background
import '@toolbox-web/grid';
import { ContextMenuPlugin } from '@toolbox-web/grid/plugins/context-menu';
grid.gridConfig = {
plugins: [
new ContextMenuPlugin({
items: [
{ id: 'copy', name: 'Copy', shortcut: 'Ctrl+C', action: (ctx) => navigator.clipboard.writeText(ctx.value) },
{ separator: true, id: 'sep1', name: '' },
{ id: 'delete', name: 'Delete', action: (ctx) => removeRow(ctx.rowIndex) },
],
}),
],
};
new ContextMenuPlugin({
items: [
{ id: 'edit', name: 'Edit', visible: (ctx) => ctx.column.editable === true },
{ id: 'delete', name: 'Delete', disabled: (ctx) => ctx.row.locked === true },
],
})

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Programmatically show the context menu at the specified position.

showMenu(x: number, y: number, params: Partial<ContextMenuParams>): void
NameTypeDescription
xnumberX coordinate
ynumberY coordinate
paramsPartial<ContextMenuParams>Partial context menu parameters

Hide the context menu.

hideMenu(): void

Check if the context menu is currently open.

isMenuOpen(): boolean

boolean - Whether the menu is open


AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt