DataGridXL - API

ContextMenu

Description

The ContextMenu (shared between all DataGridXL instances) is the menu that appears when right-clicking inside a DataGridXL Renderer.

Usage

The DataGridXL class has a static property contextMenu.

javascript
// create DataGridXL instance
const grid = new DataGridXL(...);
// work with the shared ContextMenu instance
grid.constructor.contextMenu.selectItem(2);
grid.constructor.contextMenu.events.on('open', ...);
NOTE: You don't need to create a ContextMenu instance yourself — it is provided by the grid automatically.

Methods

close()

Close context menu

Fires$close
isOpen(): boolean

Check if context menu is open

ReturnsbooleanReturns `true` if context menu is open, otherwise `false`.
moveCursorDown()

Move cursor down inside list of items

moveCursorUp()

Move cursor up inside list of items

open(items, bounds)

Open context menu

Arguments

items
arrayArray of context menu items
bounds
objectTarget bounds in pixels `{ top, right, bottom, left }`
Fires$beforeopen$open
selectItem(index)

Select context menu item by index

Arguments

index
numberIndex of context menu item
Fires$beforeselectitem$selectitem
setCursor(index)

Set the cursor to the given index

Arguments

index
numberIndex of cursor
updateItemLabels(items)

Update item labels

Arguments

items
arrayArray of context menu items

Events

closeContextMenuEvent

Fires when context menu closes

Payload

type
string
Type of the event (e.g. 'dblclick', 'contextmenu')
target
ContextMenu
Instance that fired the event
beforeopenContextMenuOpenEvent

Fires before context menu opens You may modify `payload` to alter the behavior Returning `false` cancels the event.

Payload

type
string
Always `"beforeopen"` or `"open"`
target
ContextMenu
Instance that fired the event
payload
ContextMenuOpenEventPayload
Structured event data
openContextMenuOpenEvent

Fires when context menu opens

Payload

type
string
Always `"beforeopen"` or `"open"`
target
ContextMenu
Instance that fired the event
payload
ContextMenuOpenEventPayload
Structured event data
beforeselectitemContextMenuSelectItemEvent

Fires before a context menu item is selected You may modify `payload` to alter the behavior Returning `false` cancels the event.

Payload

type
string
Always `"beforeselectitem"` or `"selectitem"`
target
ContextMenu
Instance that fired the event
payload
ContextMenuSelectItemEventPayload
Structured event data
selectitemContextMenuSelectItemEvent

Fires when a context menu item is selected

Payload

type
string
Always `"beforeselectitem"` or `"selectitem"`
target
ContextMenu
Instance that fired the event
payload
ContextMenuSelectItemEventPayload
Structured event data