Overview
DataGrid manages the filter state but does not render filter inputs. Build the filter UI
with @mantine/core components and connect it to the store:
interface DataGridStore<TData extends RowData = any> {
/** Active column filters, each with an id and value. */
columnFilters: ColumnFiltersState;
/** Set one filter. Pass undefined, null or '' to remove it. */
setColumnFilter: (columnId: string, value: unknown) => void;
getColumnFilterValue: (columnId: string) => unknown;
/** Replace all column filters, or update them from the previous state. */
setColumnFilters: (updater: Updater<ColumnFiltersState>) => void;
resetColumnFilters: () => void;
/** Distinct column values. Requires withFaceting. */
getFacetedUniqueValues: (columnId: string) => DataGridFacetedValue[];
/** Numeric column range. Requires withFaceting. */
getFacetedMinMaxValues: (columnId: string) => [number, number] | undefined;
/** Global search value and setter. */
globalFilter: any;
setGlobalFilter: (value: any) => void;
}Column filtering is enabled automatically when any column has enableColumnFilter: true or
filterFn. Set withFiltering: true to enable it for all columns.
Rows are filtered with filterFn of the column. It is the name of a built-in TanStack Table
filter function, for example includesString or inNumberRange, or your own function.
Global search
Pass withGlobalFilter to useDataGrid to enable search across all columns.
DataGrid.GlobalFilter renders the search input, DataGrid.Toolbar without children includes it.
To use your own input, connect it with store.getGlobalFilter() and store.setGlobalFilter():
First Name | Last Name | Email | Department | Salary |
|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 |
| Carol | Williams | carol.williams@example.com | Sales | 68000 |
| David | Brown | david.brown@example.com | HR | 65000 |
| Eva | Davis | eva.davis@example.com | Finance | 88000 |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 |
| James | Thomas | james.thomas@example.com | Finance | 91000 |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 |
| Leo | White | leo.white@example.com | Engineering | 110000 |
| Mia | Harris | mia.harris@example.com | Sales | 74000 |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 |
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { TextInput } from '@mantine/core';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'email', header: 'Email', size: 220 },
{ accessorKey: 'department', header: 'Department' },
{ accessorKey: 'salary', header: 'Salary' },
],
withGlobalFilter: true,
});
return (
<>
<TextInput
placeholder="Search..."
value={store.getGlobalFilter() ?? ''}
onChange={(event) => store.setGlobalFilter(event.currentTarget.value)}
mb="md"
/>
<DataGrid store={store} />
</>
);
}Filters popover
A Filters button in the toolbar opens a popover with one control per filterable column.
Controls read values with getColumnFilterValue and write them with setColumnFilter:
First Name | Last Name | Email | Department | Status |
|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | active |
| Bob | Smith | bob.smith@example.com | Marketing | active |
| Carol | Williams | carol.williams@example.com | Sales | active |
| David | Brown | david.brown@example.com | HR | inactive |
| Eva | Davis | eva.davis@example.com | Finance | active |
| Frank | Miller | frank.miller@example.com | Engineering | active |
| Grace | Wilson | grace.wilson@example.com | Marketing | active |
| Henry | Taylor | henry.taylor@example.com | Sales | inactive |
| Irene | Anderson | irene.anderson@example.com | Engineering | active |
| James | Thomas | james.thomas@example.com | Finance | active |
| Karen | Jackson | karen.jackson@example.com | HR | active |
| Leo | White | leo.white@example.com | Engineering | active |
| Mia | Harris | mia.harris@example.com | Sales | active |
| Nathan | Martin | nathan.martin@example.com | Marketing | inactive |
| Olivia | Garcia | olivia.garcia@example.com | Finance | active |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | active |
| Quinn | Robinson | quinn.robinson@example.com | HR | active |
| Rachel | Clark | rachel.clark@example.com | Sales | active |
import { Badge, Button, Group, Popover, Select, Stack, TextInput } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name', enableColumnFilter: true },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'email', header: 'Email', size: 220 },
{ accessorKey: 'department', header: 'Department', filterFn: 'equals' },
{ accessorKey: 'status', header: 'Status', filterFn: 'equals' },
],
withFaceting: true,
});
const activeCount = store.getColumnFilters().length;
return (
<DataGrid store={store}>
<DataGrid.Toolbar>
<Popover position="bottom-start" shadow="md">
<Popover.Target>
<Button
size={store.getControlSize()}
variant="default"
rightSection={activeCount > 0 ? <Badge size="xs" circle>{activeCount}</Badge> : null}
>
Filters
</Button>
</Popover.Target>
<Popover.Dropdown>
<Stack gap="sm" w={240}>
<TextInput
label="First name"
placeholder="Contains"
value={(store.getColumnFilterValue('firstName') as string) ?? ''}
onChange={(event) => store.setColumnFilter('firstName', event.currentTarget.value)}
/>
<Select
label="Department"
placeholder="Any"
clearable
data={store.getFacetedUniqueValues('department')}
value={(store.getColumnFilterValue('department') as string) ?? null}
onChange={(value) => store.setColumnFilter('department', value)}
/>
<Select
label="Status"
placeholder="Any"
clearable
data={store.getFacetedUniqueValues('status')}
value={(store.getColumnFilterValue('status') as string) ?? null}
onChange={(value) => store.setColumnFilter('status', value)}
/>
<Group justify="flex-end">
<Button
size="xs"
variant="default"
disabled={activeCount === 0}
onClick={() => store.resetColumnFilters()}
>
Clear all
</Button>
</Group>
</Stack>
</Popover.Dropdown>
</Popover>
</DataGrid.Toolbar>
</DataGrid>
);
}Faceted filters
Pass withFaceting: true to useDataGrid to get unique values and numeric ranges of columns
from the data:
getFacetedUniqueValues(columnId)returns{ value, label }[]that can be passed asdatatoSelectorMultiSelectgetFacetedMinMaxValues(columnId)returns[min, max]forRangeSlideror number inputs
Use the matching filterFn: equals for a single value, arrIncludesSome for multiple values
and inNumberRange for a range:
Salary
First Name | Last Name | Department | Status | Salary |
|---|---|---|---|---|
| Alice | Johnson | Engineering | active | 95000 |
| Bob | Smith | Marketing | active | 72000 |
| Carol | Williams | Sales | active | 68000 |
| David | Brown | HR | inactive | 65000 |
| Eva | Davis | Finance | active | 88000 |
| Frank | Miller | Engineering | active | 102000 |
| Grace | Wilson | Marketing | active | 76000 |
| Henry | Taylor | Sales | inactive | 71000 |
| Irene | Anderson | Engineering | active | 97000 |
| James | Thomas | Finance | active | 91000 |
| Karen | Jackson | HR | active | 63000 |
| Leo | White | Engineering | active | 110000 |
| Mia | Harris | Sales | active | 74000 |
| Nathan | Martin | Marketing | inactive | 69000 |
| Olivia | Garcia | Finance | active | 85000 |
| Patrick | Martinez | Engineering | active | 99000 |
| Quinn | Robinson | HR | active | 67000 |
| Rachel | Clark | Sales | active | 73000 |
import { Button, Group, RangeSlider, Select, Text } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'department', header: 'Department', filterFn: 'equals' },
{ accessorKey: 'status', header: 'Status', filterFn: 'equals' },
{
accessorKey: 'salary',
header: 'Salary',
filterFn: 'inNumberRange',
meta: { align: 'end' },
},
],
withFaceting: true,
});
const [min, max] = store.getFacetedMinMaxValues('salary') ?? [0, 0];
const range = (store.getColumnFilterValue('salary') as [number, number] | undefined) ?? [min, max];
return (
<DataGrid store={store}>
<DataGrid.Toolbar>
<Select
size={store.getControlSize()}
placeholder="Department"
clearable
data={store.getFacetedUniqueValues('department')}
value={(store.getColumnFilterValue('department') as string) ?? null}
onChange={(value) => store.setColumnFilter('department', value)}
/>
<Select
size={store.getControlSize()}
placeholder="Status"
clearable
data={store.getFacetedUniqueValues('status')}
value={(store.getColumnFilterValue('status') as string) ?? null}
onChange={(value) => store.setColumnFilter('status', value)}
/>
<Group gap="xs" wrap="nowrap" style={{ flex: 1, minWidth: 220 }}>
<Text size="xs" c="dimmed">
Salary
</Text>
<RangeSlider
size="sm"
style={{ flex: 1 }}
min={min}
max={max}
step={1000}
minRange={1000}
value={range}
label={(value) => `$${value.toLocaleString()}`}
onChange={(value) => store.setColumnFilter('salary', value)}
/>
</Group>
<Button
size={store.getControlSize()}
variant="default"
disabled={store.getColumnFilters().length === 0}
onClick={() => store.resetColumnFilters()}
>
Reset
</Button>
</DataGrid.Toolbar>
</DataGrid>
);
}Operator filters
stringOperators, numberOperators and booleanOperators are sets of filter operators:
contains, equals, starts with, is empty, greater than, etc. Set
filterFn: createOperatorFilterFn(stringOperators) on the column and use an
{ operator, value } object as its filter value. To define your own operators,
pass an array of FilterOperator objects to createOperatorFilterFn:
First Name | Last Name | Department | Salary |
|---|---|---|---|
| Alice | Johnson | Engineering | 95000 |
| Bob | Smith | Marketing | 72000 |
| Carol | Williams | Sales | 68000 |
| David | Brown | HR | 65000 |
| Eva | Davis | Finance | 88000 |
| Frank | Miller | Engineering | 102000 |
| Grace | Wilson | Marketing | 76000 |
| Henry | Taylor | Sales | 71000 |
| Irene | Anderson | Engineering | 97000 |
| James | Thomas | Finance | 91000 |
| Karen | Jackson | HR | 63000 |
| Leo | White | Engineering | 110000 |
| Mia | Harris | Sales | 74000 |
| Nathan | Martin | Marketing | 69000 |
| Olivia | Garcia | Finance | 85000 |
| Patrick | Martinez | Engineering | 99000 |
| Quinn | Robinson | HR | 67000 |
| Rachel | Clark | Sales | 73000 |
import { useState } from 'react';
import { Group, NumberInput, Select, TextInput } from '@mantine/core';
import {
createOperatorFilterFn,
DataGrid,
numberOperators,
OperatorFilterValue,
stringOperators,
useDataGrid,
} from '@mantine/data-grid';
import { employees } from './data';
const stringOperatorOptions = stringOperators.map(({ value, label }) => ({ value, label }));
const numberOperatorOptions = numberOperators.map(({ value, label }) => ({ value, label }));
function Demo() {
const [nameOperator, setNameOperator] = useState('contains');
const [salaryOperator, setSalaryOperator] = useState('gte');
const store = useDataGrid({
data: employees,
columns: [
{
accessorKey: 'firstName',
header: 'First Name',
filterFn: createOperatorFilterFn(stringOperators),
},
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'department', header: 'Department' },
{
accessorKey: 'salary',
header: 'Salary',
filterFn: createOperatorFilterFn(numberOperators),
meta: { align: 'end' },
},
],
});
const nameValue = (store.getColumnFilterValue('firstName') as OperatorFilterValue | undefined)
?.value;
const salaryValue = (store.getColumnFilterValue('salary') as OperatorFilterValue | undefined)
?.value;
const nameValueless = stringOperators.find((op) => op.value === nameOperator)?.valueless;
const setNameFilter = (operator: string, value: unknown) => {
const valueless = stringOperators.find((op) => op.value === operator)?.valueless;
store.setColumnFilter('firstName', valueless || value ? { operator, value } : undefined);
};
const setSalaryFilter = (operator: string, value: unknown) => {
store.setColumnFilter('salary', value === '' ? undefined : { operator, value });
};
return (
<DataGrid store={store}>
<DataGrid.Toolbar>
<Group gap={4} wrap="nowrap">
<Select
size={store.getControlSize()}
w={130}
allowDeselect={false}
data={stringOperatorOptions}
value={nameOperator}
onChange={(operator) => {
if (operator) {
setNameOperator(operator);
setNameFilter(operator, nameValue);
}
}}
/>
<TextInput
size={store.getControlSize()}
placeholder="First name"
disabled={nameValueless}
value={typeof nameValue === 'string' ? nameValue : ''}
onChange={(event) => setNameFilter(nameOperator, event.currentTarget.value)}
/>
</Group>
<Group gap={4} wrap="nowrap">
<Select
size={store.getControlSize()}
w={72}
allowDeselect={false}
data={numberOperatorOptions}
value={salaryOperator}
onChange={(operator) => {
if (operator) {
setSalaryOperator(operator);
setSalaryFilter(operator, salaryValue ?? '');
}
}}
/>
<NumberInput
size={store.getControlSize()}
placeholder="Salary"
prefix="$"
thousandSeparator
value={typeof salaryValue === 'number' ? salaryValue : ''}
onChange={(value) => setSalaryFilter(salaryOperator, value)}
/>
</Group>
</DataGrid.Toolbar>
</DataGrid>
);
}Filter chips
Render store.getColumnFilters() as removable pills to show active filters. Use the getColumnLabel
function exported from @mantine/data-grid to get the column label:
First Name | Last Name | Department | Status | Salary |
|---|---|---|---|---|
| Alice | Johnson | Engineering | active | 95000 |
| Bob | Smith | Marketing | active | 72000 |
| Carol | Williams | Sales | active | 68000 |
| David | Brown | HR | inactive | 65000 |
| Eva | Davis | Finance | active | 88000 |
| Frank | Miller | Engineering | active | 102000 |
| Grace | Wilson | Marketing | active | 76000 |
| Henry | Taylor | Sales | inactive | 71000 |
| Irene | Anderson | Engineering | active | 97000 |
| James | Thomas | Finance | active | 91000 |
| Karen | Jackson | HR | active | 63000 |
| Leo | White | Engineering | active | 110000 |
| Mia | Harris | Sales | active | 74000 |
| Nathan | Martin | Marketing | inactive | 69000 |
| Olivia | Garcia | Finance | active | 85000 |
| Patrick | Martinez | Engineering | active | 99000 |
| Quinn | Robinson | HR | active | 67000 |
| Rachel | Clark | Sales | active | 73000 |
import { Button, Pill, Popover, Select, Stack, TextInput } from '@mantine/core';
import { DataGrid, getColumnLabel, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name', enableColumnFilter: true },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'department', header: 'Department', filterFn: 'equals' },
{ accessorKey: 'status', header: 'Status', filterFn: 'equals' },
{ accessorKey: 'salary', header: 'Salary', meta: { align: 'end' } },
],
withFaceting: true,
});
return (
<DataGrid store={store}>
<DataGrid.Toolbar>
<Popover position="bottom-start" shadow="md">
<Popover.Target>
<Button size={store.getControlSize()} variant="default">
Add filter
</Button>
</Popover.Target>
<Popover.Dropdown>
<Stack gap="sm" w={220}>
<TextInput
label="First name"
placeholder="Contains"
value={(store.getColumnFilterValue('firstName') as string) ?? ''}
onChange={(event) => store.setColumnFilter('firstName', event.currentTarget.value)}
/>
<Select
label="Department"
placeholder="Any"
clearable
data={store.getFacetedUniqueValues('department')}
value={(store.getColumnFilterValue('department') as string) ?? null}
onChange={(value) => store.setColumnFilter('department', value)}
/>
<Select
label="Status"
placeholder="Any"
clearable
data={store.getFacetedUniqueValues('status')}
value={(store.getColumnFilterValue('status') as string) ?? null}
onChange={(value) => store.setColumnFilter('status', value)}
/>
</Stack>
</Popover.Dropdown>
</Popover>
{store.getColumnFilters().map((filter) => {
const column = store.table.getColumn(filter.id);
return column ? (
<Pill
key={filter.id}
size={store.getControlSize()}
withRemoveButton
onRemove={() => store.setColumnFilter(filter.id, undefined)}
>
{getColumnLabel(column)}: {String(filter.value)}
</Pill>
) : null;
})}
{store.getColumnFilters().length > 0 && (
<Button size={store.getControlSize()} variant="default" onClick={() => store.resetColumnFilters()}>
Clear all
</Button>
)}
</DataGrid.Toolbar>
</DataGrid>
);
}Controlled filters
Pass columnFilters and onColumnFiltersChange to useDataGrid to control filter state.
The state is an array of { id, value } objects:
Active filters: []
First Name | Last Name | Department | Salary | Status |
|---|---|---|---|---|
| Alice | Johnson | Engineering | 95000 | active |
| Bob | Smith | Marketing | 72000 | active |
| Carol | Williams | Sales | 68000 | active |
| David | Brown | HR | 65000 | inactive |
| Eva | Davis | Finance | 88000 | active |
| Frank | Miller | Engineering | 102000 | active |
| Grace | Wilson | Marketing | 76000 | active |
| Henry | Taylor | Sales | 71000 | inactive |
| Irene | Anderson | Engineering | 97000 | active |
| James | Thomas | Finance | 91000 | active |
| Karen | Jackson | HR | 63000 | active |
| Leo | White | Engineering | 110000 | active |
| Mia | Harris | Sales | 74000 | active |
| Nathan | Martin | Marketing | 69000 | inactive |
| Olivia | Garcia | Finance | 85000 | active |
| Patrick | Martinez | Engineering | 99000 | active |
| Quinn | Robinson | HR | 67000 | active |
| Rachel | Clark | Sales | 73000 | active |
import { useState } from 'react';
import { ColumnFiltersState } from '@tanstack/react-table';
import { Code, Text, TextInput } from '@mantine/core';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';
function Demo() {
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name', enableColumnFilter: true },
{ accessorKey: 'lastName', header: 'Last Name', enableColumnFilter: true },
{ accessorKey: 'department', header: 'Department' },
{ accessorKey: 'salary', header: 'Salary' },
{ accessorKey: 'status', header: 'Status' },
],
columnFilters,
onColumnFiltersChange: setColumnFilters,
});
return (
<>
<TextInput
placeholder="Filter by first name"
value={(store.getColumnFilterValue('firstName') as string) ?? ''}
onChange={(event) => store.setColumnFilter('firstName', event.currentTarget.value)}
mb="md"
/>
<Text mb="md">
Active filters: <Code>{JSON.stringify(columnFilters)}</Code>
</Text>
<DataGrid store={store} />
</>
);
}Custom filter functions
Set filterFn on a column definition to a function that receives the row, column id and
filter value and returns true if the row should be included:
First Name | Last Name | Department (exact match) | Salary |
|---|---|---|---|
| Alice | Johnson | Engineering | 95000 |
| Bob | Smith | Marketing | 72000 |
| Carol | Williams | Sales | 68000 |
| David | Brown | HR | 65000 |
| Eva | Davis | Finance | 88000 |
| Frank | Miller | Engineering | 102000 |
| Grace | Wilson | Marketing | 76000 |
| Henry | Taylor | Sales | 71000 |
| Irene | Anderson | Engineering | 97000 |
| James | Thomas | Finance | 91000 |
| Karen | Jackson | HR | 63000 |
| Leo | White | Engineering | 110000 |
| Mia | Harris | Sales | 74000 |
| Nathan | Martin | Marketing | 69000 |
| Olivia | Garcia | Finance | 85000 |
| Patrick | Martinez | Engineering | 99000 |
| Quinn | Robinson | HR | 67000 |
| Rachel | Clark | Sales | 73000 |
import { TextInput } from '@mantine/core';
import { DataGrid, DataGridFilterFn, useDataGrid } from '@mantine/data-grid';
import { employees } from './data';
const exactMatchFilter: DataGridFilterFn = (row, columnId, filterValue) => {
if (!filterValue) {
return true;
}
const cellValue = String(row.getValue(columnId));
return cellValue === filterValue;
};
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'department', header: 'Department (exact match)', filterFn: exactMatchFilter },
{ accessorKey: 'salary', header: 'Salary' },
],
});
return (
<>
<TextInput
placeholder="Department, exact match (e.g. Engineering)"
value={(store.getColumnFilterValue('department') as string) ?? ''}
onChange={(event) => store.setColumnFilter('department', event.currentTarget.value)}
mb="md"
/>
<DataGrid store={store} />
</>
);
}Disable filtering per column
Set enableColumnFilter: false on a column definition to disable filtering of that column:
const store = useDataGrid({
data,
withFiltering: true,
columns: [
{ accessorKey: 'id', header: 'ID', enableColumnFilter: false },
{ accessorKey: 'name', header: 'Name' },
{ accessorKey: 'email', header: 'Email' },
],
});Global filter column exclusion
Set enableGlobalFilter: false on a column definition to exclude the column from the global search:
First Name | Last Name | Email (excluded) | Department | Salary (excluded) |
|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 |
| Carol | Williams | carol.williams@example.com | Sales | 68000 |
| David | Brown | david.brown@example.com | HR | 65000 |
| Eva | Davis | eva.davis@example.com | Finance | 88000 |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 |
| James | Thomas | james.thomas@example.com | Finance | 91000 |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 |
| Leo | White | leo.white@example.com | Engineering | 110000 |
| Mia | Harris | mia.harris@example.com | Sales | 74000 |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 |
import { DataGrid, useDataGrid } from '@mantine/data-grid';
import { TextInput } from '@mantine/core';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{
accessorKey: 'email',
header: 'Email (excluded)',
size: 220,
enableGlobalFilter: false,
},
{ accessorKey: 'department', header: 'Department' },
{
accessorKey: 'salary',
header: 'Salary (excluded)',
enableGlobalFilter: false,
},
],
withGlobalFilter: true,
});
return (
<>
<TextInput
placeholder="Search..."
value={store.getGlobalFilter() ?? ''}
onChange={(event) => store.setGlobalFilter(event.currentTarget.value)}
mb="md"
/>
<DataGrid store={store} />
</>
);
}Fuzzy search
Pass fuzzyFilter exported from @mantine/data-grid as globalFilterFn to useDataGrid
for typo-tolerant global search. Use fuzzySort to sort rows by their match rank:
First Name | Last Name | Email | Department | Salary |
|---|---|---|---|---|
| Alice | Johnson | alice.johnson@example.com | Engineering | 95000 |
| Bob | Smith | bob.smith@example.com | Marketing | 72000 |
| Carol | Williams | carol.williams@example.com | Sales | 68000 |
| David | Brown | david.brown@example.com | HR | 65000 |
| Eva | Davis | eva.davis@example.com | Finance | 88000 |
| Frank | Miller | frank.miller@example.com | Engineering | 102000 |
| Grace | Wilson | grace.wilson@example.com | Marketing | 76000 |
| Henry | Taylor | henry.taylor@example.com | Sales | 71000 |
| Irene | Anderson | irene.anderson@example.com | Engineering | 97000 |
| James | Thomas | james.thomas@example.com | Finance | 91000 |
| Karen | Jackson | karen.jackson@example.com | HR | 63000 |
| Leo | White | leo.white@example.com | Engineering | 110000 |
| Mia | Harris | mia.harris@example.com | Sales | 74000 |
| Nathan | Martin | nathan.martin@example.com | Marketing | 69000 |
| Olivia | Garcia | olivia.garcia@example.com | Finance | 85000 |
| Patrick | Martinez | patrick.martinez@example.com | Engineering | 99000 |
| Quinn | Robinson | quinn.robinson@example.com | HR | 67000 |
| Rachel | Clark | rachel.clark@example.com | Sales | 73000 |
import { DataGrid, fuzzyFilter, useDataGrid } from '@mantine/data-grid';
import { TextInput } from '@mantine/core';
import { employees } from './data';
function Demo() {
const store = useDataGrid({
data: employees,
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'email', header: 'Email', size: 220 },
{ accessorKey: 'department', header: 'Department' },
{ accessorKey: 'salary', header: 'Salary' },
],
withGlobalFilter: true,
globalFilterFn: fuzzyFilter,
});
return (
<>
<TextInput
placeholder="Search..."
value={store.getGlobalFilter() ?? ''}
onChange={(event) => store.setGlobalFilter(event.currentTarget.value)}
mb="md"
/>
<DataGrid store={store} />
</>
);
}Debounced and server-side filtering
For server-side filtering, set manualFiltering: true, keep the filter state controlled and
debounce it with useDebouncedValue before sending a request:
import { useState } from 'react';
import { ColumnFiltersState } from '@tanstack/react-table';
import { TextInput } from '@mantine/core';
import { useDebouncedValue } from '@mantine/hooks';
import { DataGrid, useDataGrid } from '@mantine/data-grid';
function Demo() {
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([]);
const [debouncedFilters] = useDebouncedValue(columnFilters, 300);
// Use debouncedFilters in your data fetching logic
const data = useQuery(['employees', debouncedFilters], () =>
fetchEmployees(debouncedFilters)
);
const store = useDataGrid({
data: data ?? [],
columns: [
{ accessorKey: 'firstName', header: 'First Name' },
{ accessorKey: 'lastName', header: 'Last Name' },
{ accessorKey: 'department', header: 'Department' },
],
withFiltering: true,
manualFiltering: true,
columnFilters,
onColumnFiltersChange: setColumnFilters,
});
return (
<DataGrid store={store}>
<DataGrid.Toolbar>
<TextInput
size={store.getControlSize()}
placeholder="First name"
value={(store.getColumnFilterValue('firstName') as string) ?? ''}
onChange={(event) => store.setColumnFilter('firstName', event.currentTarget.value)}
/>
</DataGrid.Toolbar>
</DataGrid>
);
}See the Server-side page for a complete example.
Empty results
When all rows are filtered out, emptyState is displayed. Use isFiltered from its payload
to offer a "Clear filters" action, see States.