Skip to main content

Header Menu

headerMenu puts a settings button in the top-right corner of the column header. Its menu holds the controls that usually take up a toolbar row, so a grid can drop the toolbar row entirely:

  • Columns: a show/hide checklist of the columns, with Show all columns at the top and a search box when there are more than 8.
  • Full screen / Exit full screen.
  • Autosize all columns.
  • Reset columns: back to the default visibility (defaultVisible), the column definition order and the default widths. onColumnsReset fires afterwards so you can clear saved column state.

The button sits in a narrow gutter at the right edge of the grid, level with the header rows, so it never covers a column and stays put while the grid scrolls. It follows the theme (dark mode included). In full screen the gutter also shows an Exit full screen button. It is a normal tab stop: Enter, Space or ArrowDown opens the menu, the arrow keys move through it, ArrowRight and ArrowLeft open and leave submenus, and Escape closes it and returns focus to the button.

Live Demo​

Open the settings button in the header's top-right corner
Live

Quick Example​

<OGrid
columns={columns}
data={rows}
getRowId={(row) => row.id}
headerMenu
/>

With headerMenu on, the toolbar's column chooser is left out unless you set columnChooser yourself. When nothing else needs the toolbar (no toolbar content, no toolbar chooser, no fullScreen button), the grid renders no toolbar row at all.

Your own items and submenus​

headerMenuItems adds items to the corner menu. Give an item items to make it open a submenu; submenus can nest.

<OGrid
headerMenu
headerMenuItems={[
{
id: 'export',
label: 'Export',
items: [
{ id: 'csv', label: 'CSV', onClick: exportCsv },
{ id: 'json', label: 'JSON', onClick: exportJson },
],
},
{ id: 'share', label: 'Copy link', onClick: copyLink },
]}
{...gridProps}
/>

An array is added after the built-in items. Pass a function to hide, reorder or wrap the built-in items: it receives them and returns the full list.

headerMenuItems={(builtIns, { isFullScreen }) => [
{ id: 'reset', label: 'Reset view', onClick: resetView },
...builtIns.filter((item) => item.id !== 'autosizeAll'),
]}

Built-in ids in the corner menu: columns, fullScreen, autosizeAll and resetColumns.

Item shape​

FieldTypeDescription
idstringStable id.
labelstringText shown.
iconReactNodeShown before the label.
onClick() => voidRuns when the item is chosen. The menu then closes, unless keepOpen is set.
itemsIGridMenuItem[]Makes the item open a submenu.
disabledbooleanGreys the item out.
checkedbooleanRenders a checkable item (menuitemcheckbox) in this state.
keepOpenbooleanKeep the menu open after onClick.
dividerbooleanSeparator after the item.
searchablebooleanFor an item with items: a search box above its submenu filters the items by label.

Column menus​

Each column's menu (its options button, or a right-click on the header) now also offers:

  • Choose columns: the same checklist as Columns above, as a submenu. Hidden with columnChooser={false}.
  • Full screen: when fullscreen is on offer (fullScreen, headerMenu or isFullScreen).

columnMenuItems customizes column menus the same way. The function form also gets the column id:

columnMenuItems={(builtIns, { columnId }) => [
...builtIns.filter((item) => !['pinLeft', 'pinRight', 'unpin'].includes(item.id)),
{ id: 'details', label: 'Column details', onClick: () => showDetails(columnId) },
]}

Built-in column menu ids: pinLeft, pinRight, unpin, moveLeft, moveRight, sortAsc, sortDesc, addToSort, clearSort, autosizeThis, autosizeAll, chooseColumns, fullScreen, insertColumnLeft, insertColumnRight, deleteColumn, hideColumn and unhideColumns. Only the items that apply to the column appear.

Fullscreen shortcut​

While fullscreen is on offer, pressing F with the grid focused toggles it. It doesn't fire while a cell is being edited or focus is in a text field or menu. On an editable cell a plain letter starts an edit instead, so use a shortcut with a modifier on editable grids:

<OGrid headerMenu fullScreenShortcut="Shift+F" {...gridProps} />

Mod means Ctrl or Cmd ('Mod+Shift+F'). fullScreenShortcut={false} turns it off.

Styling​

VariableDefaultDescription
--ogrid-header-corner-width32pxWidth of the corner gutter (44px on touch screens)

Props​

PropTypeDefaultDescription
headerMenubooleanfalseShow the settings button in the header corner.
headerMenuItemsIGridMenuItem[] | (builtIns, { isFullScreen }) => IGridMenuItem[]Items for the corner menu.
columnMenuItemsIGridMenuItem[] | (builtIns, { columnId }) => IGridMenuItem[]Items for every column menu.
fullScreenShortcutstring | false'f'Key that toggles fullscreen while the grid has focus.
onColumnsReset() => voidCalled after Reset columns.
isFullScreen / onFullScreenChangeControl and follow fullscreen; see OGrid props.