View as Markdown

Context Menu

Context menu

A right-click and Shift+F10 menu for headers, cells, rows, group captions and the pager, with built-in and custom items and per-target control.

contextMenu replaces the browser menu inside the grid. contextMenu={true} shows a default menu per target: auto-size, group, sort and pin items on headers; edit, copy and export items on cells; page items on the pager.

Items

An array lists the items in order for every target: built-in ids and custom DataGridMenuItem objects.

  • Columns: autoSize, autoSizeAll, sortAscending, sortDescending, group, ungroup, pinStart, pinEnd, unpin.
  • Rows: edit, delete, save, cancel, copy.
  • Export: exportExcel, exportPdf, exportCsv.
  • Pager: firstPage, previousPage, nextPage, lastPage (need paging).

Built-ins that cannot apply to the target are dropped, for example edit, delete and copy on a header or the pager, and sort and pin items on the pager. Page items apply to every target while paging is on; the demo keeps them on the pager through onBeforeContextMenuOpen. Custom items take the same fields as column menu items (id, label, icon, disabled, targets, href), with nested items for submenus. A submenu opens when the pointer rests on its item for a moment (200 ms hover intent) and closes when the pointer rests on a sibling; crossing a sibling on the way into the submenu keeps it open. From the keyboard, ArrowRight opens it (ArrowLeft in RTL) and ArrowLeft or Escape closes it.

Edit, copy and export items run UI commands. Without a handler for the command (api.registerCommandHandler) or a module that declares it, the item is disabled and its tooltip says which feature is missing.

Targets and events

The menu opens for a header, a cell, a row, a group caption or the pager. onBeforeContextMenuOpen receives that target as a descriptor ({ kind: 'cell', rowId, field }, { kind: 'header', field }, ...) and a mutable copy of the items: edit event.items in place (splice, push) to change the menu for this target (the event object is frozen in development, so never reassign event.items), or call preventDefault() to keep it closed. onBeforeContextMenuClose can keep it open.

onContextMenuItemClick reports the item, the target and rowIds: the target row, or the whole selection when the target row is selected, with rows() to read the row objects. preventDefault() skips the built-in action. renderContextMenu replaces the menu and receives the target, the resolved items, the defaultMenu element and close().

The target is resolved from the row and column ids of the clicked element, so the menu works the same on virtualized rows and pinned columns. Shift+F10 and the ContextMenu key open it for the focused cell, header or group caption, and on a focused pager button for the pager target; Escape closes it and returns focus to that element.

Context menu

Open demo

Right-click (or Shift+F10) a header, cell or the pager over 5,000 rows with a pinned column; the default per-target menus or a custom list with built-ins, a submenu and a custom action; per-target items and cancelation in onBeforeContextMenuOpen; disabled export items with a reason.

Order
Customer
Country
Product
Priority
Amount
Placed
ORD-10000
Jun Park
Portugal
Oolong tea
Low
$114.75
Sep 21, 2026
ORD-10001
Hana Sato
France
Oolong tea
High
$133.24
Jun 27, 2026
ORD-10002
Jun Park
Japan
Filter beans
Low
$63.00
Dec 18, 2026
ORD-10003
Chen Wei
Germany
Green tea
Low
$111.00
Dec 12, 2026
ORD-10004
Dewi Lestari
France
Kettle
Normal
$408.87
May 9, 2026
ORD-10005
Farah Aziz
Malaysia
Espresso beans
Normal
$35.15
Oct 15, 2026
ORD-10006
Goran Petrov
Malaysia
Grinder
High
$548.25
Apr 28, 2026
ORD-10007
Jun Park
Japan
Oolong tea
Low
$86.70
Mar 27, 2026
ORD-10008
Bao Nguyen
Germany
Pour-over kit
Low
$189.00
Oct 27, 2026
ORD-10009
Bao Nguyen
Malaysia
Oolong tea
Low
$126.23
May 15, 2026
ORD-10010
Ines Duarte
Malaysia
Green tea
High
$74.93
Jun 24, 2026
ORD-10011
Bao Nguyen
Japan
Kettle
Normal
$713.90
Jul 3, 2026
ORD-10012
Elif Kaya
Malaysia
Oolong tea
Low
$96.90
Mar 21, 2026
ORD-10013
Farah Aziz
Portugal
Green tea
Normal
$70.30
Mar 2, 2026
ORD-10014
Bao Nguyen
Malaysia
Green tea
Normal
$92.50
Jul 26, 2026
ORD-10015
Goran Petrov
Portugal
Espresso beans
Normal
$158.17
Jul 1, 2026
ORD-10016
Bao Nguyen
Germany
Espresso beans
Normal
$149.85
Aug 7, 2026
ORD-10017
Jun Park
Malaysia
Filter beans
High
$151.20
Aug 16, 2026
ORD-10018
Elif Kaya
France
Pour-over kit
Low
$321.30
Jul 5, 2026
ORD-10019
Jun Park
Malaysia
Espresso beans
Normal
$105.45
Jun 10, 2026
No events yet.

API reference

DataGridContextMenuItemId lists the built-in ids, DataGridMenuItem the custom item fields and DataGridContextMenuTarget the target descriptors; DataGridContextMenuOpenEvent and DataGridContextMenuItemClickEvent are the event payloads.