Skip to content

Cell context menu ​

Right-click a cell and the actions available for that cell appear as a menu. With the keyboard, select a cell and press Shift+F10 (or the ContextMenu key). The menu is on by default.

It has cut, copy, copy with headers, paste, note actions and export. Try it in the gallery example Cell context menu.

Default items ​

Item (id)What it does
Cut (cut)Copies the selected cells to the clipboard and clears them. Disabled if not editable
Copy (copy)Copies the selected cells as text split by tabs and line breaks
Copy with headers (copy-headers)Adds the column titles as the first line
Copy with group headersAlso adds the column group titles. Shown only when the grid has header groups
Paste (paste)Fills cells from the clipboard. Disabled if the cell is not editable or reading is blocked
Add, edit or remove noteAttaches a note to the cell (Cell notes)
Export (export)Downloads CSV, Excel or PDF. Shown only on a grid that has export methods attached

How copy, cut and paste behave is covered in Copy and paste. The export item appears only on a grid where you called withExport(api) (CSV, Excel and PDF export). Without it the item is not there at all.

Turn it off ​

cellMenu is on by default. Pass false and right-click goes back to the browser menu, and the note shortcut (Shift+F2) turns off too. The copy and paste keys keep working regardless of this option.

ts
createGrid(el, { columns, rows, rowKey: 'id', cellMenu: false });

Add and remove items ​

Pass an object and use the items callback. It receives the default items and returns the list to show. It runs every time the menu opens, and its second argument says which cell the menu opened on (rowKey, columnId, row, api).

ts
createGrid(el, {
  columns,
  rows,
  rowKey: 'id',
  cellMenu: {
    items: (defaults, { row, api }) => [
      ...defaults.filter((item) => item.id !== 'export'), // hide export
      { id: 'sep-mine', label: '', separator: true },
      {
        id: 'open',
        label: `Open details for ${row.name}`,
        run: () => openDetail(row.id),
      },
    ],
  },
});

An item has these fields.

FieldMeaning
idThe item name. Use it to pick out default items
labelThe visible text
shortcutDimmed key hint on the right. It only displays text
disabledIf true, the item cannot be chosen
separatorIf true, only a divider line is drawn there
childrenIf present, a submenu opens on the right
runFunction called when chosen. The menu closes first

If the returned list is empty the menu does not open. The default id values are cut, copy, copy-headers, copy-group-headers, paste, note-add, note-edit, note-remove and export.

Export file name ​

The export items download files named like grid.csv. Change the base name with exportFilename, without an extension.

ts
cellMenu: { exportFilename: 'employees' }, // employees.csv, employees.xlsx, employees.pdf

Right-click and long-press events, and intercepting them ​

Before a menu opens, contextMenuRequested { zone, rowKey, columnId, x, y, event } fires once (1.3.6). Then beforeContextMenu decides whether the built-in menu opens, so a vetoed request is still visible as an event. zone is cell, header, rownum or rownum-header. When a long press opens it, event is null. It fires even with cellMenu: false, so you can attach your own menu.

ts
hooks: {
  // false: no built-in menu and the browser menu is left alone
  beforeContextMenu: ({ zone, columnId }) => (zone === 'header' && columnId === 'id' ? false : undefined),
},
cellMenu: { allowWithCtrl: false }, // Ctrl+right-click shows the browser menu
EventValueWhen
cellMenuOpened, cellMenuClosed{ rowKey, columnId }The cell menu opens and closes
columnMenuOpened, columnMenuClosed{ columnId }The column menu opens and closes
cellLongPressed{ rowKey, columnId, x, y }A cell is held by touch for 400 ms
cellMouseOver, cellMouseOut, cellMouseDown{ rowKey, columnId, event }The mouse enters, leaves or presses a cell
headerMouseOver, headerMouseOut{ columnId, event }The mouse enters or leaves a header

Mouse events attach their DOM listeners only while someone subscribes, so they cost nothing otherwise (onAny subscribes to everything, so it attaches them). A long press is cancelled when the finger moves more than a little (10 px) or the grid scrolls. A long press opens the cell menu at that spot.

Keyboard use ​

KeyAction
Shift+F10 or ContextMenuOpens the menu below the focused cell
Up, Down, Home, EndMoves between items, wrapping at the ends
RightOpens a submenu. Left closes it
Enter or SpaceRuns the highlighted item
EscCloses the open submenu, or the menu itself, and returns to the cell
TabCloses the menu and lets the browser move focus

In text inputs and cells being edited these keys are left to the browser. The open menu closes when sorting, filtering, rows or columns change, or when the grid scrolls.

Change the text ​

Menu text comes from the messages option. Override cellMenuLabel, cellCut, cellCopy, cellCopyHeaders, cellCopyGroupHeaders, cellPaste, cellNoteAdd, cellNoteEdit, cellNoteRemove, cellExport, cellExportCsv, cellExportXlsx or cellExportPdf. Keys you leave out use the locale defaults.

ts
messages: { cellCopy: 'Copy cells', cellPaste: 'Paste here' },

If the browser blocks reading the clipboard, the menu's paste cannot work and a short notice appears under the grid. Its text is cellPasteBlocked. In that case select a cell and press Ctrl+V.

See also ​