View as Markdown

Toolbar

Toolbar

Built-in and custom toolbar items, alignment, search, overflow, keyboard navigation and a replaceable toolbar.

The toolbar prop lists the items in order. The toolbar renders as a role="toolbar" element just before the role="grid" element, not inside it: a grid may only own rows, so a toolbar inside it would break the grid semantics. In DOM order the toolbar comes first, so Tab reaches the toolbar and then the grid's single tab stop.

Built-in items

Built-in items are plain ids: 'add', 'edit', 'delete', 'save', 'cancel', 'search', 'print', 'columnChooser', 'exportExcel', 'exportPdf' and 'exportCsv', plus the Salmon UI additions 'expandAll' and 'collapseAll' for groups, 'copy' (copies the selection), 'filterBuilder' (opens the filter builder; needs filtering.builder, see Filtering), and 'indent' and 'outdent' for tree rows (see Tree Grid). 'search' renders a search box bound to the grid search (it needs the search prop), and 'columnChooser' opens the column chooser below the button.

Edit, copy, export, print and tree items run named UI commands (edit.add, clipboard.copy, export.csv, grid.print, tree.indent, ...). An item is enabled when something serves its command: a handler registered with api.registerCommandHandler, or a registered module that declares it. Otherwise the item is disabled with the reason as its tooltip.

With editing on, the edit items also follow the edit state. 'add', 'edit' and 'delete' need editing.add, editing.edit and editing.delete; 'edit' and 'delete' also need a target row: a selected row or cell range, or with selection off the focused body cell. In row, dialog and cell mode an open edit disables 'add', 'edit' and 'delete', and only then are 'save' (Update) and 'cancel' enabled. In batch mode 'save' and 'cancel' are enabled while there are pending changes (edited, added or deleted rows) or a cell editor is open. These items are aria-disabled and do nothing until the state changes; the toolbar re-renders only when an item's enablement can change, never per cell or keystroke.

<DataGrid
  aria-label="Orders"
  data={orders}
  columns={columns}
  grouping
  toolbar={['expandAll', 'collapseAll', { id: 'columnChooser', label: 'Columns' }, 'exportCsv', 'search']}
  search
  onReady={(api) => api.registerCommandHandler('export.csv', () => { /* export */ return true; })}
/>

Custom items

An item object is a DataGridToolbarItem: id, label, icon, title (tooltip), align, disabled and render for custom content. An object whose id is a built-in id keeps the built-in behavior and takes the new label, icon, title, alignment or disabled. disabled is reactive: pass a new value and the item updates.

Give a render item a label: it names the button (aria-label, so an icon-only render stays accessible) and is the item's text in the overflow menu. Without one the menu falls back to title, then the rendered text or aria-label, then the id, and development builds warn once.

Items align to the start (default), center or end of the toolbar; the search box defaults to end.

onToolbarItemClick reports every click with the item; calling event.preventDefault() skips the built-in action. renderToolbar replaces the toolbar and receives the resolved items, the defaultToolbar element to wrap and the grid api.

Overflow and keyboard

When the items do not fit, the trailing items move into a "more" menu at the end of the toolbar; the search box always stays visible. The toolbar measures itself and updates as the grid resizes. The toolbar is one tab stop with roving focus: ArrowLeft and ArrowRight move between items (mirrored in RTL), and Home and End jump to the first and last item.

Toolbar

Open demo

Built-in items (search, column chooser, expand and collapse all, export, print), built-ins with a custom label, custom items with reactive disabled, a centered custom render item, the overflow menu at a narrow width, renderToolbar, and onToolbarItemClick with preventDefault().

Order
Customer
Country
Product
Priority
Amount
Note
Country: France - 256 items
ORD-10000
Hana Sato
France
Filter beans
Normal
$75.60
ORD-10003
Farah Aziz
France
Grinder
Normal
$774.00
ORD-10013
Chen Wei
France
Kettle
Normal
$292.05
Leave the parcel with the building reception if nobody answers the door.
ORD-10014
Ines Duarte
France
Green tea
Normal
$55.50
Call before delivery
ORD-10019
Dewi Lestari
France
Pour-over kit
Normal
$142.80
Call before delivery
ORD-10028
Jun Park
France
Espresso beans
Low
$47.18
ORD-10030
Hana Sato
France
Kettle
Normal
$408.87
ORD-10033
Dewi Lestari
France
Pour-over kit
High
$37.80
ORD-10039
Bao Nguyen
France
Espresso beans
High
$31.45
Call before delivery
ORD-10043
Hana Sato
France
Espresso beans
Low
$148.00
ORD-10046
Hana Sato
France
Filter beans
High
$71.40
Gift wrap
ORD-10056
Bao Nguyen
France
Pour-over kit
Normal
$504.00
ORD-10058
Goran Petrov
France
Filter beans
Normal
$75.60
ORD-10062
Hana Sato
France
Pour-over kit
High
$294.00
ORD-10068
Jun Park
France
Pour-over kit
Low
$378.00
Gift wrap
ORD-10070
Jun Park
France
Oolong tea
Normal
$51.00
Gift wrap
ORD-10075
Bao Nguyen
France
Pour-over kit
High
$214.20
ORD-10077
Hana Sato
France
Kettle
High
$525.69
ORD-10084
Bao Nguyen
France
Filter beans
High
$84.00
No events yet.

API reference

DataGridToolbarItem and DataGridToolbarItemId describe the items, DataGridToolbarItemClickEvent the click event, DataGridToolbarContext the renderToolbar context, and DataGridApi registerCommandHandler.