Context menu
The built-in cell context menu, how to add, replace or remove items, and how modules contribute their own.
Right-click a cell, or press Shift+F10 or the context menu key on a focused cell, to open the grid's cell menu. By default it offers:
| Item | Result |
|---|---|
| Copy cell | Copies the cell's formatted value |
| Copy row | Copies the row as tab-separated text; when the row is part of a multi-row selection, every selected row is copied (Copy selected rows) |
| Copy with headers | The same, with a header line first |
| Export CSV | Calls downloadCsv() |
Copied text is tab-separated, so it pastes cleanly into Excel, Google Sheets or the Birch UI Spreadsheet. Grid Pro modules add their own items, such as copying a range.
Changing the items#
contextMenu takes true (the default), false, or a function that receives the cell and the default items and returns the items to show:
import { createGrid, type MenuItem } from '@birchui/core';
const grid = createGrid<Order>(el, {
columns,
rows: orders,
getRowId: (order) => order.id,
contextMenu: (ctx, defaults) => {
const order = ctx.row;
if (!order) return defaults;
const items: MenuItem[] = [
{ label: 'Open order', action: () => openOrder(order.id) },
{ label: 'Mark as shipped', disabled: order.status !== 'Pending', action: () => markShipped(order.id) },
{ label: 'Flag for review', checked: order.flagged, action: () => toggleFlag(order.id) },
];
return [...items, { ...defaults[0], separatorBefore: true }, ...defaults.slice(1)];
},
});Return an empty array to show no menu for that cell; the browser's own menu then stays out of the way only when you call preventDefault yourself, so prefer contextMenu: false to restore the native menu everywhere.
Behaviour#
- The menu does not open on full-width rows (group rows rendered full width, master/detail panels) or while a cell is being edited; the editor keeps the browser's menu for spelling suggestions and paste.
- Opening the menu focuses the cell it was opened on, and closing it returns focus there.
- Items are buttons in a
menuwith arrow-key navigation. Escape closes the menu. - User callbacks run inside a try/catch, so an error in an
actionis reported withconsole.errorand the grid keeps working.
The column menu#
Every header has a separate column menu (the button at the right of the header, or Alt+Arrow Down on a focused header). It holds sort, pin, autosize, hide and show items, and Filter… for filterable columns, which opens the filter popup.
From a module#
Modules contribute cell menu items with internals.addContextMenuItems((ctx) => items) and column menu items with internals.addColumnMenuItems((column) => items). Both return a function that removes the provider. See Modules.
Related#
- Keyboard and accessibility
- CSV export
- Clipboard in Grid Pro