Toolbar options
Look up the props of DataGridToolbar, DataGridSearch, DataGridFilterMenu, DataGridColumnsMenu, and DataGridHeaderFilter.
The toolbar add-on exports five components. DataGridToolbar is the frame. DataGridSearch, DataGridFilterMenu, and DataGridColumnsMenu sit inside it. DataGridHeaderFilter mounts in the header through the renderHeaderFilter slot.
| Component | Purpose | Guide |
|---|---|---|
DataGridToolbar | Lays out the toolbar slots | Toolbar |
DataGridSearch | Quick search input | Quick search |
DataGridFilterMenu | Filter popover | Filtering |
DataGridColumnsMenu | Shows and hides columns | Toolbar |
DataGridHeaderFilter | Value list in a column header | Header filter |
This sample mounts all five components:
import {
DataGridBody,
DataGridHeader,
DataGridProvider,
DataGridRoot,
type ColumnDef,
} from "@/components/data-grid/data-grid";
import {
DataGridColumnsMenu,
DataGridFilterMenu,
DataGridHeaderFilter,
DataGridSearch,
DataGridToolbar,
} from "@/components/data-grid-toolbar/data-grid-toolbar";
type Person = { id: string; name: string };
const people: Person[] = [{ id: "1", name: "Ada" }];
const columns: ColumnDef<Person>[] = [
{ id: "name", accessorKey: "name", header: "Name" },
];
export function PeopleGrid() {
return (
<DataGridProvider defaultData={people} columns={columns}>
<DataGridToolbar>
<DataGridSearch debounceMs={300} />
<DataGridFilterMenu allColumns />
<DataGridColumnsMenu />
</DataGridToolbar>
<DataGridRoot
renderHeaderFilter={(ctx) => <DataGridHeaderFilter {...ctx} />}
>
<DataGridHeader />
<DataGridBody />
</DataGridRoot>
</DataGridProvider>
);
}Import the components from @/components/data-grid-toolbar/data-grid-toolbar. Every component accepts className. DataGridHeaderFilter merges it into its button.
DataGridToolbar
Prop
Type
Place it inside DataGridProvider, above DataGridRoot. Its children share the store of the grid.
DataGridSearch
Prop
Type
focusSearch
The focusSearch action of the keymap prop binds Mod+F by default. While focus is inside this grid or its toolbar, the key focuses the input and leaves the browser find bar closed. Focus anywhere else keeps the browser behavior. The handler skips a key press that another handler already handled. keymap={{ focusSearch: [] }} leaves the key to the browser. With the find and replace add-on, Mod+F opens its Find panel, and focusSearch loses the key.
A plugin binding that takes the focusSearch key warns once in development, unless the plugin is find and replace. Set keymap.focusSearch to keep a search key, or to [] to hand the key over.
DataGridFilterMenu
Operator list
The menu picks the operator list of a column in this order:
- The
filter.operatorsof the column. - The
filter.operatorsof the cell type. - The default list for the cell type.
allColumns
Without allColumns, the field select offers the visible columns. A filter on a hidden column keeps applying, and its row shows that column with its own operators.
DataGridColumnsMenu
The menu shows and hides columns. It has no pin controls.
DataGridHeaderFilter
Prop
Type
Spread the context of the renderHeaderFilter slot into the component. The slot passes column and index. className adds classes to the trigger button. setFilterOperator fixes the operator of the set entry the popover writes.
This slot renders a darker trigger:
renderHeaderFilter={(ctx) => (
<DataGridHeaderFilter {...ctx} className="text-foreground" />
)}Server mode
Without fetchFilterValues, the value list of DataGridHeaderFilter and the isAnyOf and isNoneOf inputs of a column without choices read the loaded rows. Pass fetchFilterValues to DataGridProvider to read the values from your server. The header filter page describes the request.