#Context Menu
The context menu is the menu the grid shows when the user right-clicks a cell. Adaptable ships a built-in menu, and you can replace or extend it with your own menus — one default menu for all views, or a different menu per view.
Context menus are plain state: you define them under contextMenu.availableMenus
and reference them by id from your views.
#Defining context menus
Each key in contextMenu.availableMenus is the id of a menu; the value is its
definition — a label and a getMenuItems function that returns the items to
show.
getMenuItems runs every time the user right-clicks, so the items can depend on
the cell that was clicked. It receives a single object with:
adaptableApi— the Adaptable API.cellValue— the value of the clicked cell.column— the Adaptable column that was clicked.undefinedwhen the user clicked outside a cell.currentView— the current view, computed (it carries more than the view definition in state).items— the menu items Adaptable would show by default. Return them as they are, extend them, or leave them out.menu— the context menu definition being rendered.rowInfo— the Infinite Table row info of the clicked row (userowInfo.isGroupRowto tell group rows apart).undefinedwhen the user clicked outside a row.
The items are Infinite Table menu items: objects with a key and a label,
plus optional disabled, description, menu (a submenu with its own items)
and onAction, or the '-' separator.
What you return decides what the user sees:
- an array of items — that menu is shown;
- an empty array — no menu at all, not even the browser's;
null— no Adaptable menu, so the browser's own context menu opens.
Put anything that repeats across menus in contextMenu.menuDefaults — it is
merged under every menu definition, and each menu's own properties win.
#Responding to clicks
Use the item's onAction to react to the user picking it. Because the item is
created inside getMenuItems, onAction has access to the clicked cell — no
lookups needed.
getMenuItems: ({ items, cellValue, column, rowInfo }) => [
...items,
'-',
{
key: 'show-cell-value',
label: 'Show cell value',
onAction: ({ hideMenu }) => {
hideMenu();
if (!column || !rowInfo) {
return;
}
alert(`"${cellValue}" (column "${column.id}", row ${rowInfo.id})`);
},
},
],The menu stays open after an action unless you call hideMenu() (as above) or
set hideMenuOnAction: true on the item.
#A default context menu for all views
To use the same menu in every view, set view.viewDefaults.contextMenu to the
id of a menu from availableMenus.
#A view-specific context menu
To override the default for one view, set that view's contextMenu property to
another menu id. A view's own contextMenu always wins over
viewDefaults.contextMenu; a view with neither shows the built-in menu.
#The built-in items
The items passed to getMenuItems are what Adaptable shows when no menu is
configured:
- Show Settings — opens the settings panel.
- Export — a submenu listing the export reports and their destinations
(disabled for users without the
export_runpermission — see Permissioning). - Remove Flashing — shown on a cell that is currently flashing (see Flashing Cells).
- Add note / Show notes / Delete notes — on a cell, from the Cell Notes module.
Modules excluded via the modules prop don't contribute items.