Context menu
The right-click menu of a cell with copy, paste, pin, hide, export and print, and contextMenu to add, reorder or replace its items.
Paid feature · Context menu. Free for 30 days on a new domain; after that it needs a free personal key or a company key. See pricing
Right-click a cell, or press Shift+F10 or the menu key on the focused cell, and the grid opens its own menu instead of the browser's: copy, copy with headers, cut and paste, copy the checked rows, undo and redo, delete the checked rows, autosize, hide and pin the column, select all rows, choose columns, charts of the selected range, export to CSV, Excel, JSON and PDF, the advanced filter and print. Items that do not apply, such as undo with nothing to undo, are left out or greyed out.
Pass a function as contextMenu to change it. It receives the cell (row, rowIndex, colId, value) and defaultItems, the menu the grid would show; return the items to show, keeping, reordering or extending the defaults. An item has a label and an action, and may be disabled or show a shortcut; 'separator' draws a line. contextMenu: false keeps the browser's menu.
const grid = createGrid(el, {
columns,
data,
contextMenu: p => [
...p.defaultItems, // Copy, Paste, Pin, Hide, Export …
'separator',
{ label: 'Open order', action: () => open(p.row) },
{ label: 'Delete', action: () => grid.removeRows([p.row]), disabled: !p.row?.draft, shortcut: 'Del' },
],
// contextMenu: false, // keep the browser's own menu
});Right-clicking a column header opens the column menu (sort, filter, pin, hide), which is free and not affected by this option, unless you set headerContextMenu (below).
Building your own menu
contextMenu and headerContextMenu build your own menus with built-in keys, submenus, icons, check marks and headings. See:
Options
| Name | Type | Description |
|---|---|---|
contextMenu | false | ContextMenuItem[] | (params) => ContextMenuItem[] | false keeps the browser's menu; a list or a function gives the items to show. |
headerContextMenu | false | true | ContextMenuItem[] | (params) => ContextMenuItem[] | A right-click menu on column headers (sort, pin, group, size, hide…). true: the built-in one. Left out: headers open the column menu. |
params | { area, row, rowIndex, colId, column, value, defaultItems } | Where the menu opened: area 'cell' or 'header' (rowIndex -1, row null), and the built-in items to keep, reorder or extend. Actions get the same params. |
ContextMenuItem | 'separator' | ContextMenuKey | { heading } | { label, action?, items?, icon?, checked?, disabled?, hidden?, danger?, shortcut?, title? } | A line, a built-in entry by name, a small title, or an entry. items makes a submenu; icon takes text, an emoji, an element or an SVG string. |
ContextMenuKey | string | copy, copyWithHeaders, cut, copyRows, paste, undo, redo, deleteRows, autosize, autosizeAll, hideColumn, pinLeft, pinRight, unpin, selectAll, chooseColumns, resetColumns, chartBar, chartLine, chartPie, exportCsv, exportExcel, exportJson, exportPdf, advancedFilter, print, sortAsc, sortDesc, clearSort, groupBy, ungroup, conditionalFormat, columnMenu |