Filter Variants Example
Material React Table has not only has filtering built-in, but it has a lot of different filter variants that take care of a lot of the heavy lifting for you. Text filters, date filters, range filters, range slider filters, and more are all built-in and ready to use. There is a ton more you can do to customize the behavior of filtering, so be sure to check out the full Column Filtering Feature Guide for more information.
Status | Name | Salary | Hire Date | Age | City Filter by City | State Filter by State |
---|---|---|---|---|---|---|
Active | Tanner Linsley | $100,000.00 | 2/23/2016 | 42 | San Francisco | California |
Active | Kevin Vandy | $80,000.00 | 2/23/2019 | 51 | Richmond | Virginia |
Inactive | John Doe | $120,000.00 | 2/23/2014 | 27 | Riverside | South Carolina |
Active | Jane Doe | $150,000.00 | 2/25/2015 | 32 | San Francisco | California |
Inactive | John Smith | $75,000.00 | 6/11/2023 | 42 | Los Angeles | California |
Active | Jane Smith | $56,000.00 | 2/23/2019 | 51 | Blacksburg | Virginia |
Inactive | Samuel Jackson | $90,000.00 | 2/23/2010 | 27 | New York | New York |
10
1-7 of 7
1import { useMemo } from 'react';2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';3import { citiesList, data, type Person, usStateList } from './makeData';45const Example = () => {6 const columns = useMemo<MRT_ColumnDef<Person>[]>(7 () => [8 {9 header: 'Status',10 accessorFn: (originalRow) => (originalRow.isActive ? 'true' : 'false'), //must be strings11 id: 'isActive',12 filterVariant: 'checkbox',13 Cell: ({ cell }) =>14 cell.getValue() === 'true' ? 'Active' : 'Inactive',15 size: 170,16 },17 {18 accessorKey: 'name',19 header: 'Name',20 filterVariant: 'text', // default21 size: 200,22 },23 {24 accessorKey: 'salary',25 header: 'Salary',26 Cell: ({ cell }) =>27 cell.getValue<number>().toLocaleString('en-US', {28 style: 'currency',29 currency: 'USD',30 }),31 filterVariant: 'range-slider',32 filterFn: 'betweenInclusive', // default (or between)33 muiFilterSliderProps: {34 marks: true,35 max: 200_000, //custom max (as opposed to faceted max)36 min: 30_000, //custom min (as opposed to faceted min)37 step: 10_000,38 valueLabelFormat: (value) =>39 value.toLocaleString('en-US', {40 style: 'currency',41 currency: 'USD',42 }),43 },44 },45 {46 accessorFn: (originalRow) => new Date(originalRow.hireDate), //convert to date for sorting and filtering47 id: 'hireDate',48 header: 'Hire Date',49 filterVariant: 'date-range',50 Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(), // convert back to string for display51 },52 {53 accessorKey: 'age',54 header: 'Age',55 filterVariant: 'range',56 filterFn: 'between',57 size: 80,58 },59 {60 accessorKey: 'city',61 header: 'City',62 filterVariant: 'select',63 filterSelectOptions: citiesList, //custom options list (as opposed to faceted list)64 },65 {66 accessorKey: 'state',67 header: 'State',68 filterVariant: 'multi-select',69 filterSelectOptions: usStateList, //custom options list (as opposed to faceted list)70 },71 ],72 [],73 );7475 return (76 <MaterialReactTable77 columns={columns}78 data={data}79 initialState={{ showColumnFilters: true }}80 />81 );82};8384//Date Picker Imports - these should just be in your Context Provider85import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';86import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';8788const ExampleWithLocalizationProvider = () => (89 //App.tsx or AppProviders file90 <LocalizationProvider dateAdapter={AdapterDayjs}>91 <Example />92 </LocalizationProvider>93);9495export default ExampleWithLocalizationProvider;96
View Extra Storybook Examples