Faceted Values Example
Material React Table can scan your data and automatically generate filter autocomplete suggestions, filter select options, or min and max values for your column filters. This is made possible by the faceted values feature from TanStack Table. Learn more in the full Column Filtering Feature Guide.
Name | Salary | City Filter by City | State Filter by State |
---|---|---|---|
Tanner Linsley | $100,000.00 | San Francisco | California |
Kevin Vandy | $80,000.00 | Richmond | Virginia |
John Doe | $120,000.00 | Riverside | South Carolina |
Jane Doe | $150,000.00 | San Francisco | California |
John Smith | $75,000.00 | Los Angeles | California |
Jane Smith | $56,000.00 | Blacksburg | Virginia |
Samuel Jackson | $90,000.00 | New York | New York |
10
1-7 of 7
1import { useMemo } from 'react';2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';3import { data, type Person } from './makeData';45const Example = () => {6 const columns = useMemo<MRT_ColumnDef<Person>[]>(7 () => [8 {9 accessorKey: 'name',10 header: 'Name',11 filterVariant: 'autocomplete', // default12 size: 100,13 },14 {15 accessorKey: 'salary',16 header: 'Salary',17 Cell: ({ cell }) =>18 cell.getValue<number>().toLocaleString('en-US', {19 style: 'currency',20 currency: 'USD',21 }),22 filterVariant: 'range-slider',23 filterFn: 'betweenInclusive', // default (or between)24 muiFilterSliderProps: {25 //no need to specify min/max/step if using faceted values26 marks: true,27 step: 5_000,28 valueLabelFormat: (value) =>29 value.toLocaleString('en-US', {30 style: 'currency',31 currency: 'USD',32 }),33 },34 },35 {36 accessorKey: 'city',37 header: 'City',38 filterVariant: 'select',39 //no need to specify filterSelectOptions if using faceted values40 },41 {42 accessorKey: 'state',43 header: 'State',44 filterVariant: 'multi-select',45 //no need to specify filterSelectOptions if using faceted values46 },47 ],48 [],49 );5051 return (52 <MaterialReactTable53 columns={columns}54 data={data}55 enableFacetedValues56 initialState={{ showColumnFilters: true }}57 />58 );59};6061export default Example;62
View Extra Storybook Examples