Skip to content

Body Context Menu

Right-clicking any data, hierarchy, pivot, or pinned cell — or pressing Shift+F10 / ContextMenu on a focused body position — opens the body context menu without moving logical focus or clearing selection.

Body Context Menu (Clipboard, Export & Custom Actions)
import { Grid, type ColumnDef } from 'next-grid-js';
import { createOrders, type OrderRow } from './data/orders';
import { syncGridTheme } from './theme';
import type { DemoMountContext } from './types';
export function mount({ stage, meta }: DemoMountContext): () => void {
const columnDefs: readonly ColumnDef<OrderRow>[] = [
{
key: 'id',
name: 'ID',
width: 96,
},
{
key: 'customer',
name: 'Customer',
width: 175,
flex: 1,
isEditable: true,
},
{
key: 'region',
name: 'Region',
width: 105,
},
{
key: 'amount',
name: 'Amount',
width: 115,
cellDataType: 'number',
formatter: ({ value }) =>
`$${Number(value).toLocaleString('en-US')}`,
},
];
const grid = new Grid<OrderRow>({
container: stage,
columnDefs,
rowData: createOrders(20),
getRowId: (row) => row.id,
cellSelection: { mode: 'range' },
clipboard: { copyMode: 'formatted' },
dataExport: { formats: ['csv', 'json'] },
bodyMenu: {
getMenuItems: ({ params, defaultItems }) => [
...defaultItems,
{
kind: 'builtin',
id: 'copy-with-headers',
name: 'Copy with headers',
},
{ kind: 'separator' },
{
kind: 'custom',
name: 'Inspect target',
action: () => {
const t = params.target;
meta.textContent =
t.kind === 'cell'
? `Target: ${t.colId} (row ${t.displayIndex}, inSelection=${params.isInSelection})`
: `Target: ${t.kind}`;
},
},
],
},
});
const stopTheme = syncGridTheme(stage);
meta.textContent = 'Right-click any cell or press Shift+F10';
return () => {
grid.destroy();
stopTheme();
};
}
ID Behavior Module Requirement (./core)
'copy' Copies selection if target is inside it, else target cell ClipboardModule
'copy-row' Copies selected rows or target row (excluding checkbox column) ClipboardModule
'copy-with-headers' Like 'copy', prefixed with leaf column headers (opt-in via getMenuItems) ClipboardModule
'paste' Pastes TSV into selection or starting at target cell ClipboardModule
'export-csv', 'export-xlsx', 'export-json', 'export-markdown' Triggers download in that format using dataExport options ExportModule
  • Outside Selection (.grid-menu-target): When right-clicking outside the active selection, params.isInSelection is false and the clicked cell/row gets .grid-menu-target while the menu is open.
  • Native Menu Fallback: Returning [] from getMenuItems, setting bodyMenu: false, or omitting clipboard/dataExport without custom items opens the native browser menu. Native <input>, editable controls, links, and selection checkboxes always preserve the native menu.
  • Limits: Maximum 64 total items and 32 custom items; action callbacks must be synchronous.