@lminii/material-react-table 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -234
- package/locales/ja/index.d.mts +0 -3
- package/locales/ja/index.d.ts +0 -3
- package/locales/ja/package.json +0 -6
- package/package.json +147 -147
- package/skills/README.md +81 -81
- package/skills/composable-components/SKILL.md +189 -189
- package/skills/customization/SKILL.md +190 -190
- package/skills/drag-and-drop-ordering/SKILL.md +227 -227
- package/skills/editing/SKILL.md +243 -243
- package/skills/filtering/SKILL.md +213 -213
- package/skills/getting-started/SKILL.md +213 -213
- package/skills/localization/SKILL.md +182 -182
- package/skills/migrate-v3-to-v4/SKILL.md +161 -161
- package/skills/state-and-server-data/SKILL.md +200 -200
- package/skills/virtualization/SKILL.md +203 -203
|
@@ -1,213 +1,213 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: filtering
|
|
3
|
-
description: >
|
|
4
|
-
Configure column and global filtering in Material React Table V4: filterVariant (text, select, multi-select, autocomplete, range, range-slider, checkbox, date, datetime, time and their ranges), enableFacetedValues, filterFn and filterFns, enableColumnFilterModes with columnFilterModeOptions, columnFilterDisplayMode, globalFilterFn and ranked results, filter match highlighting, and the muiFilter*Props. Load for dropdown or date filters, custom filter logic, filter mode menus, or search that matches the wrong rows.
|
|
5
|
-
metadata:
|
|
6
|
-
type: framework
|
|
7
|
-
library: '@lminii/material-react-table'
|
|
8
|
-
library_version: '4.0.0'
|
|
9
|
-
framework: react
|
|
10
|
-
requires:
|
|
11
|
-
- getting-started
|
|
12
|
-
- '@tanstack/table-core#column-filtering'
|
|
13
|
-
- '@tanstack/table-core#global-filtering'
|
|
14
|
-
sources:
|
|
15
|
-
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/column-filtering.mdx'
|
|
16
|
-
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/global-filtering.mdx'
|
|
17
|
-
- 'lminii/material-react-table:apps/material-react-table-docs/examples/customize-filter-variants/sandbox/src/TS.tsx'
|
|
18
|
-
- 'lminii/material-react-table:packages/material-react-table/src/fns/filterFns.ts'
|
|
19
|
-
- 'lminii/material-react-table:packages/material-react-table/src/utils/column.utils.ts'
|
|
20
|
-
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
This skill builds on `getting-started`, `@tanstack/table-core#column-filtering`, and `@tanstack/table-core#global-filtering`. Client-side column filters and the global search are on by default. MRT adds filter inputs, filter variants, fuzzy matching, and filter mode menus on top of the TanStack filtering model; server-side filtering is covered by `state-and-server-data`.
|
|
24
|
-
|
|
25
|
-
## Setup
|
|
26
|
-
|
|
27
|
-
```tsx
|
|
28
|
-
const columns: MRT_ColumnDef<Person>[] = [
|
|
29
|
-
{ accessorKey: 'name', header: 'Name' }, // text filter, fuzzy
|
|
30
|
-
{ accessorKey: 'city', header: 'City', filterVariant: 'select' },
|
|
31
|
-
{ accessorKey: 'state', header: 'State', filterVariant: 'multi-select' },
|
|
32
|
-
{ accessorKey: 'salary', header: 'Salary', filterVariant: 'range-slider' },
|
|
33
|
-
{
|
|
34
|
-
accessorFn: (row) => new Date(row.hireDate), // filter and sort on a Date
|
|
35
|
-
id: 'hireDate',
|
|
36
|
-
header: 'Hired',
|
|
37
|
-
filterVariant: 'date-range',
|
|
38
|
-
Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(),
|
|
39
|
-
},
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
const table = useMaterialReactTable({
|
|
43
|
-
columns,
|
|
44
|
-
data,
|
|
45
|
-
enableFacetedValues: true, // options and min/max come from the data
|
|
46
|
-
initialState: { showColumnFilters: true },
|
|
47
|
-
})
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
`enableColumnFilters` (table) and `enableColumnFilter` (column) turn column filters off; `enableGlobalFilter` does the same for search; `enableFilters: false` removes both. `showColumnFilters` and `showGlobalFilter` are state slices, so seed them in `initialState` to show the inputs immediately.
|
|
51
|
-
|
|
52
|
-
## Core Patterns
|
|
53
|
-
|
|
54
|
-
### Pick the variant and let it pick the filter function
|
|
55
|
-
|
|
56
|
-
```tsx
|
|
57
|
-
{ accessorKey: 'isActive', accessorFn: (row) => (row.isActive ? 'true' : 'false'), id: 'isActive', header: 'Active', filterVariant: 'checkbox' },
|
|
58
|
-
{ accessorKey: 'age', header: 'Age', filterVariant: 'range', filterFn: 'between' },
|
|
59
|
-
{ accessorKey: 'team', header: 'Team', filterVariant: 'autocomplete', filterSelectOptions: teams },
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
Variants: `text` (default), `autocomplete`, `select`, `multi-select`, `range`, `range-slider`, `checkbox`, `date`, `date-range`, `datetime`, `datetime-range`, `time`, `time-range`. The default `filterFn` follows the variant: `multi-select` uses `arrIncludesSome`, any `range` variant uses `betweenInclusive`, `select` and `checkbox` use `equals`, everything else uses `fuzzy`. `filterSelectOptions` takes strings or `{ label, value }` objects; with `enableFacetedValues` the select, multi-select, autocomplete, and range-slider inputs fill themselves from the column's unique values or min and max. The checkbox variant compares against the strings `'true'` and `'false'`, so its accessor must return strings.
|
|
63
|
-
|
|
64
|
-
### Date, datetime, and time variants need the pickers provider
|
|
65
|
-
|
|
66
|
-
```tsx
|
|
67
|
-
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
68
|
-
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
69
|
-
|
|
70
|
-
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
71
|
-
<MaterialReactTable table={table} />
|
|
72
|
-
</LocalizationProvider>
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
MRT renders `@mui/x-date-pickers` V9 components for these variants and expects one `LocalizationProvider` above the table. The accessor should return a `Date` so comparisons and sorting work. `muiFilterDatePickerProps`, `muiFilterDateTimePickerProps`, and `muiFilterTimePickerProps` forward props to the picker; for range variants the callback form receives `rangeFilterIndex` (0 for the start input, 1 for the end).
|
|
76
|
-
|
|
77
|
-
### Custom filter functions
|
|
78
|
-
|
|
79
|
-
```tsx
|
|
80
|
-
const table = useMaterialReactTable({
|
|
81
|
-
columns: [
|
|
82
|
-
{ accessorKey: 'name', header: 'Name', filterFn: 'startsWith' }, // MRT built-in
|
|
83
|
-
{ accessorKey: 'code', header: 'Code', filterFn: 'includesStringSensitive' }, // TanStack built-in
|
|
84
|
-
{ accessorKey: 'tags', header: 'Tags', filterFn: 'hasAllTags' }, // registered below
|
|
85
|
-
],
|
|
86
|
-
data,
|
|
87
|
-
filterFns: {
|
|
88
|
-
hasAllTags: (row, columnId, filterValue: string) =>
|
|
89
|
-
filterValue.split(',').every((tag) => row.getValue<string[]>(columnId).includes(tag.trim())),
|
|
90
|
-
},
|
|
91
|
-
globalFilterFn: 'contains', // default is 'fuzzy'
|
|
92
|
-
})
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
MRT built-ins: `between`, `betweenInclusive`, `contains`, `empty`, `endsWith`, `equals`, `fuzzy`, `greaterThan`, `greaterThanOrEqualTo`, `lessThan`, `lessThanOrEqualTo`, `notEmpty`, `notEquals`, `startsWith`. TanStack built-ins such as `includesString`, `equalsString`, `arrIncludes`, `arrIncludesAll`, `arrIncludesSome`, `weakEquals`, and `inNumberRange` also work by name. A function passed to `filterFn` receives `(row, columnId, filterValue)` and returns a boolean; functions registered in `filterFns` become names usable in `filterFn`, `globalFilterFn`, and the filter mode menus. The `fuzzy` global filter ranks rows by match quality unless `enableGlobalFilterRankedResults` is false, a sort is active, rows are expanded, or a `manual*` option is set.
|
|
96
|
-
|
|
97
|
-
### Let users switch filter modes
|
|
98
|
-
|
|
99
|
-
```tsx
|
|
100
|
-
const table = useMaterialReactTable({
|
|
101
|
-
columns: [
|
|
102
|
-
{ accessorKey: 'name', header: 'Name', columnFilterModeOptions: ['fuzzy', 'contains', 'startsWith'] },
|
|
103
|
-
{ accessorKey: 'age', header: 'Age', columnFilterModeOptions: ['between', 'lessThan', 'greaterThan'] },
|
|
104
|
-
],
|
|
105
|
-
data,
|
|
106
|
-
enableColumnFilterModes: true,
|
|
107
|
-
enableGlobalFilterModes: true,
|
|
108
|
-
globalFilterModeOptions: ['fuzzy', 'startsWith'],
|
|
109
|
-
columnFilterDisplayMode: 'popover', // 'subheader' (default), 'popover', or 'custom'
|
|
110
|
-
})
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
The chosen modes live in the `columnFilterFns` and `globalFilterFn` state slices, controllable through `onColumnFilterFnsChange` and `onGlobalFilterFnChange`. `renderColumnFilterModeMenuItems` and `renderGlobalFilterModeMenuItems` replace the menu; each receives `onSelectFilterMode(name)` and `internalFilterOptions`. `columnFilterDisplayMode: 'custom'` keeps the filtering logic while you render inputs elsewhere with `column.setFilterValue`. Filter values arrive after a short debounce (200 ms client-side, 400 ms with `manualFiltering`).
|
|
114
|
-
|
|
115
|
-
### Keep match highlighting in custom cells
|
|
116
|
-
|
|
117
|
-
```tsx
|
|
118
|
-
{
|
|
119
|
-
accessorKey: 'name',
|
|
120
|
-
header: 'Name',
|
|
121
|
-
Cell: ({ renderedCellValue }) => <strong>{renderedCellValue}</strong>,
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
Text filters and the global search highlight matches inside cells. A custom `Cell` keeps that only when it renders `renderedCellValue` instead of `cell.getValue()`. `enableFilterMatchHighlighting: false` turns it off per table or per column.
|
|
126
|
-
|
|
127
|
-
## Common Mistakes
|
|
128
|
-
|
|
129
|
-
### HIGH Filter variant does not match the accessor value type
|
|
130
|
-
|
|
131
|
-
Wrong:
|
|
132
|
-
|
|
133
|
-
```tsx
|
|
134
|
-
{ accessorKey: 'hireDate', header: 'Hired', filterVariant: 'date-range' } // hireDate is an ISO string
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
Correct:
|
|
138
|
-
|
|
139
|
-
```tsx
|
|
140
|
-
{
|
|
141
|
-
accessorFn: (row) => new Date(row.hireDate),
|
|
142
|
-
id: 'hireDate',
|
|
143
|
-
header: 'Hired',
|
|
144
|
-
filterVariant: 'date-range',
|
|
145
|
-
Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(),
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
The `betweenInclusive` comparison the date variants use works on `Date` objects and numbers, not on date strings, so string columns silently match everything or nothing.
|
|
150
|
-
|
|
151
|
-
Source: `docs/examples/customize-filter-variants`
|
|
152
|
-
|
|
153
|
-
### HIGH Reading the filter value with the wrong shape
|
|
154
|
-
|
|
155
|
-
Wrong:
|
|
156
|
-
|
|
157
|
-
```tsx
|
|
158
|
-
filterFn: (row, id, filterValue) => row.getValue<number>(id) >= filterValue, // range variant
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Correct:
|
|
162
|
-
|
|
163
|
-
```tsx
|
|
164
|
-
filterFn: (row, id, [min, max]: [number, number]) => {
|
|
165
|
-
const value = row.getValue<number>(id)
|
|
166
|
-
return (min === '' || value >= min) && (max === '' || value <= max)
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
Range variants store `[min, max]` and multi-select stores an array; text, select, and checkbox store a single value. Match the shape or the custom function throws or filters everything out.
|
|
171
|
-
|
|
172
|
-
Source: `packages/material-react-table/src/fns/filterFns.ts`
|
|
173
|
-
|
|
174
|
-
### MEDIUM Passing removed Material UI text field props to filters
|
|
175
|
-
|
|
176
|
-
Wrong:
|
|
177
|
-
|
|
178
|
-
```tsx
|
|
179
|
-
muiFilterTextFieldProps: { InputProps: { startAdornment: <SearchIcon /> } }
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
Correct:
|
|
183
|
-
|
|
184
|
-
```tsx
|
|
185
|
-
muiFilterTextFieldProps: { slotProps: { input: { startAdornment: <SearchIcon /> } } }
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
Material UI V9 removed `InputProps` and `inputProps`; MRT merges `slotProps.input`, `slotProps.htmlInput`, and `slotProps.select` into its own.
|
|
189
|
-
|
|
190
|
-
Source: `MIGRATION.md`
|
|
191
|
-
|
|
192
|
-
### MEDIUM Mode menu offers a function that is not registered
|
|
193
|
-
|
|
194
|
-
Wrong:
|
|
195
|
-
|
|
196
|
-
```tsx
|
|
197
|
-
columnFilterModeOptions: ['fuzzy', 'isPrime'], // isPrime only exists in the column's filterFn
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
Correct:
|
|
201
|
-
|
|
202
|
-
```tsx
|
|
203
|
-
filterFns: { isPrime: (row, id) => isPrime(row.getValue<number>(id)) },
|
|
204
|
-
columnFilterModeOptions: ['fuzzy', 'isPrime'],
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
Filter mode names resolve through the table `filterFns` map. A name that is not there falls back to the default and the menu label shows the raw key.
|
|
208
|
-
|
|
209
|
-
Source: `docs/guides/column-filtering.mdx`
|
|
210
|
-
|
|
211
|
-
## API Discovery
|
|
212
|
-
|
|
213
|
-
Search `node_modules/@lminii/material-react-table/dist/index.d.ts` for `filterVariant`, `MRT_FilterOption`, `filterFns`, and `muiFilter` for the exact unions and callback props. `MRT_FilterFns` is exported for reuse. The Column Filtering and Global Filtering guides at `/docs/guides/column-filtering` and `/docs/guides/global-filtering` list the related table, column, and state options, and `/docs/examples/customize-filter-variants`, `customize-filter-modes`, `enable-filter-facet-values`, and `alternate-column-filtering` are runnable examples.
|
|
1
|
+
---
|
|
2
|
+
name: filtering
|
|
3
|
+
description: >
|
|
4
|
+
Configure column and global filtering in Material React Table V4: filterVariant (text, select, multi-select, autocomplete, range, range-slider, checkbox, date, datetime, time and their ranges), enableFacetedValues, filterFn and filterFns, enableColumnFilterModes with columnFilterModeOptions, columnFilterDisplayMode, globalFilterFn and ranked results, filter match highlighting, and the muiFilter*Props. Load for dropdown or date filters, custom filter logic, filter mode menus, or search that matches the wrong rows.
|
|
5
|
+
metadata:
|
|
6
|
+
type: framework
|
|
7
|
+
library: '@lminii/material-react-table'
|
|
8
|
+
library_version: '4.0.0'
|
|
9
|
+
framework: react
|
|
10
|
+
requires:
|
|
11
|
+
- getting-started
|
|
12
|
+
- '@tanstack/table-core#column-filtering'
|
|
13
|
+
- '@tanstack/table-core#global-filtering'
|
|
14
|
+
sources:
|
|
15
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/column-filtering.mdx'
|
|
16
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/pages/docs/guides/global-filtering.mdx'
|
|
17
|
+
- 'lminii/material-react-table:apps/material-react-table-docs/examples/customize-filter-variants/sandbox/src/TS.tsx'
|
|
18
|
+
- 'lminii/material-react-table:packages/material-react-table/src/fns/filterFns.ts'
|
|
19
|
+
- 'lminii/material-react-table:packages/material-react-table/src/utils/column.utils.ts'
|
|
20
|
+
- 'lminii/material-react-table:packages/material-react-table/src/types.ts'
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
This skill builds on `getting-started`, `@tanstack/table-core#column-filtering`, and `@tanstack/table-core#global-filtering`. Client-side column filters and the global search are on by default. MRT adds filter inputs, filter variants, fuzzy matching, and filter mode menus on top of the TanStack filtering model; server-side filtering is covered by `state-and-server-data`.
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
const columns: MRT_ColumnDef<Person>[] = [
|
|
29
|
+
{ accessorKey: 'name', header: 'Name' }, // text filter, fuzzy
|
|
30
|
+
{ accessorKey: 'city', header: 'City', filterVariant: 'select' },
|
|
31
|
+
{ accessorKey: 'state', header: 'State', filterVariant: 'multi-select' },
|
|
32
|
+
{ accessorKey: 'salary', header: 'Salary', filterVariant: 'range-slider' },
|
|
33
|
+
{
|
|
34
|
+
accessorFn: (row) => new Date(row.hireDate), // filter and sort on a Date
|
|
35
|
+
id: 'hireDate',
|
|
36
|
+
header: 'Hired',
|
|
37
|
+
filterVariant: 'date-range',
|
|
38
|
+
Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(),
|
|
39
|
+
},
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
const table = useMaterialReactTable({
|
|
43
|
+
columns,
|
|
44
|
+
data,
|
|
45
|
+
enableFacetedValues: true, // options and min/max come from the data
|
|
46
|
+
initialState: { showColumnFilters: true },
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
`enableColumnFilters` (table) and `enableColumnFilter` (column) turn column filters off; `enableGlobalFilter` does the same for search; `enableFilters: false` removes both. `showColumnFilters` and `showGlobalFilter` are state slices, so seed them in `initialState` to show the inputs immediately.
|
|
51
|
+
|
|
52
|
+
## Core Patterns
|
|
53
|
+
|
|
54
|
+
### Pick the variant and let it pick the filter function
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
{ accessorKey: 'isActive', accessorFn: (row) => (row.isActive ? 'true' : 'false'), id: 'isActive', header: 'Active', filterVariant: 'checkbox' },
|
|
58
|
+
{ accessorKey: 'age', header: 'Age', filterVariant: 'range', filterFn: 'between' },
|
|
59
|
+
{ accessorKey: 'team', header: 'Team', filterVariant: 'autocomplete', filterSelectOptions: teams },
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Variants: `text` (default), `autocomplete`, `select`, `multi-select`, `range`, `range-slider`, `checkbox`, `date`, `date-range`, `datetime`, `datetime-range`, `time`, `time-range`. The default `filterFn` follows the variant: `multi-select` uses `arrIncludesSome`, any `range` variant uses `betweenInclusive`, `select` and `checkbox` use `equals`, everything else uses `fuzzy`. `filterSelectOptions` takes strings or `{ label, value }` objects; with `enableFacetedValues` the select, multi-select, autocomplete, and range-slider inputs fill themselves from the column's unique values or min and max. The checkbox variant compares against the strings `'true'` and `'false'`, so its accessor must return strings.
|
|
63
|
+
|
|
64
|
+
### Date, datetime, and time variants need the pickers provider
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
|
|
68
|
+
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
|
|
69
|
+
|
|
70
|
+
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
71
|
+
<MaterialReactTable table={table} />
|
|
72
|
+
</LocalizationProvider>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
MRT renders `@mui/x-date-pickers` V9 components for these variants and expects one `LocalizationProvider` above the table. The accessor should return a `Date` so comparisons and sorting work. `muiFilterDatePickerProps`, `muiFilterDateTimePickerProps`, and `muiFilterTimePickerProps` forward props to the picker; for range variants the callback form receives `rangeFilterIndex` (0 for the start input, 1 for the end).
|
|
76
|
+
|
|
77
|
+
### Custom filter functions
|
|
78
|
+
|
|
79
|
+
```tsx
|
|
80
|
+
const table = useMaterialReactTable({
|
|
81
|
+
columns: [
|
|
82
|
+
{ accessorKey: 'name', header: 'Name', filterFn: 'startsWith' }, // MRT built-in
|
|
83
|
+
{ accessorKey: 'code', header: 'Code', filterFn: 'includesStringSensitive' }, // TanStack built-in
|
|
84
|
+
{ accessorKey: 'tags', header: 'Tags', filterFn: 'hasAllTags' }, // registered below
|
|
85
|
+
],
|
|
86
|
+
data,
|
|
87
|
+
filterFns: {
|
|
88
|
+
hasAllTags: (row, columnId, filterValue: string) =>
|
|
89
|
+
filterValue.split(',').every((tag) => row.getValue<string[]>(columnId).includes(tag.trim())),
|
|
90
|
+
},
|
|
91
|
+
globalFilterFn: 'contains', // default is 'fuzzy'
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
MRT built-ins: `between`, `betweenInclusive`, `contains`, `empty`, `endsWith`, `equals`, `fuzzy`, `greaterThan`, `greaterThanOrEqualTo`, `lessThan`, `lessThanOrEqualTo`, `notEmpty`, `notEquals`, `startsWith`. TanStack built-ins such as `includesString`, `equalsString`, `arrIncludes`, `arrIncludesAll`, `arrIncludesSome`, `weakEquals`, and `inNumberRange` also work by name. A function passed to `filterFn` receives `(row, columnId, filterValue)` and returns a boolean; functions registered in `filterFns` become names usable in `filterFn`, `globalFilterFn`, and the filter mode menus. The `fuzzy` global filter ranks rows by match quality unless `enableGlobalFilterRankedResults` is false, a sort is active, rows are expanded, or a `manual*` option is set.
|
|
96
|
+
|
|
97
|
+
### Let users switch filter modes
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
const table = useMaterialReactTable({
|
|
101
|
+
columns: [
|
|
102
|
+
{ accessorKey: 'name', header: 'Name', columnFilterModeOptions: ['fuzzy', 'contains', 'startsWith'] },
|
|
103
|
+
{ accessorKey: 'age', header: 'Age', columnFilterModeOptions: ['between', 'lessThan', 'greaterThan'] },
|
|
104
|
+
],
|
|
105
|
+
data,
|
|
106
|
+
enableColumnFilterModes: true,
|
|
107
|
+
enableGlobalFilterModes: true,
|
|
108
|
+
globalFilterModeOptions: ['fuzzy', 'startsWith'],
|
|
109
|
+
columnFilterDisplayMode: 'popover', // 'subheader' (default), 'popover', or 'custom'
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The chosen modes live in the `columnFilterFns` and `globalFilterFn` state slices, controllable through `onColumnFilterFnsChange` and `onGlobalFilterFnChange`. `renderColumnFilterModeMenuItems` and `renderGlobalFilterModeMenuItems` replace the menu; each receives `onSelectFilterMode(name)` and `internalFilterOptions`. `columnFilterDisplayMode: 'custom'` keeps the filtering logic while you render inputs elsewhere with `column.setFilterValue`. Filter values arrive after a short debounce (200 ms client-side, 400 ms with `manualFiltering`).
|
|
114
|
+
|
|
115
|
+
### Keep match highlighting in custom cells
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
{
|
|
119
|
+
accessorKey: 'name',
|
|
120
|
+
header: 'Name',
|
|
121
|
+
Cell: ({ renderedCellValue }) => <strong>{renderedCellValue}</strong>,
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Text filters and the global search highlight matches inside cells. A custom `Cell` keeps that only when it renders `renderedCellValue` instead of `cell.getValue()`. `enableFilterMatchHighlighting: false` turns it off per table or per column.
|
|
126
|
+
|
|
127
|
+
## Common Mistakes
|
|
128
|
+
|
|
129
|
+
### HIGH Filter variant does not match the accessor value type
|
|
130
|
+
|
|
131
|
+
Wrong:
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
{ accessorKey: 'hireDate', header: 'Hired', filterVariant: 'date-range' } // hireDate is an ISO string
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Correct:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
{
|
|
141
|
+
accessorFn: (row) => new Date(row.hireDate),
|
|
142
|
+
id: 'hireDate',
|
|
143
|
+
header: 'Hired',
|
|
144
|
+
filterVariant: 'date-range',
|
|
145
|
+
Cell: ({ cell }) => cell.getValue<Date>().toLocaleDateString(),
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
The `betweenInclusive` comparison the date variants use works on `Date` objects and numbers, not on date strings, so string columns silently match everything or nothing.
|
|
150
|
+
|
|
151
|
+
Source: `docs/examples/customize-filter-variants`
|
|
152
|
+
|
|
153
|
+
### HIGH Reading the filter value with the wrong shape
|
|
154
|
+
|
|
155
|
+
Wrong:
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
filterFn: (row, id, filterValue) => row.getValue<number>(id) >= filterValue, // range variant
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Correct:
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
filterFn: (row, id, [min, max]: [number, number]) => {
|
|
165
|
+
const value = row.getValue<number>(id)
|
|
166
|
+
return (min === '' || value >= min) && (max === '' || value <= max)
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Range variants store `[min, max]` and multi-select stores an array; text, select, and checkbox store a single value. Match the shape or the custom function throws or filters everything out.
|
|
171
|
+
|
|
172
|
+
Source: `packages/material-react-table/src/fns/filterFns.ts`
|
|
173
|
+
|
|
174
|
+
### MEDIUM Passing removed Material UI text field props to filters
|
|
175
|
+
|
|
176
|
+
Wrong:
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
muiFilterTextFieldProps: { InputProps: { startAdornment: <SearchIcon /> } }
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Correct:
|
|
183
|
+
|
|
184
|
+
```tsx
|
|
185
|
+
muiFilterTextFieldProps: { slotProps: { input: { startAdornment: <SearchIcon /> } } }
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Material UI V9 removed `InputProps` and `inputProps`; MRT merges `slotProps.input`, `slotProps.htmlInput`, and `slotProps.select` into its own.
|
|
189
|
+
|
|
190
|
+
Source: `MIGRATION.md`
|
|
191
|
+
|
|
192
|
+
### MEDIUM Mode menu offers a function that is not registered
|
|
193
|
+
|
|
194
|
+
Wrong:
|
|
195
|
+
|
|
196
|
+
```tsx
|
|
197
|
+
columnFilterModeOptions: ['fuzzy', 'isPrime'], // isPrime only exists in the column's filterFn
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Correct:
|
|
201
|
+
|
|
202
|
+
```tsx
|
|
203
|
+
filterFns: { isPrime: (row, id) => isPrime(row.getValue<number>(id)) },
|
|
204
|
+
columnFilterModeOptions: ['fuzzy', 'isPrime'],
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Filter mode names resolve through the table `filterFns` map. A name that is not there falls back to the default and the menu label shows the raw key.
|
|
208
|
+
|
|
209
|
+
Source: `docs/guides/column-filtering.mdx`
|
|
210
|
+
|
|
211
|
+
## API Discovery
|
|
212
|
+
|
|
213
|
+
Search `node_modules/@lminii/material-react-table/dist/index.d.ts` for `filterVariant`, `MRT_FilterOption`, `filterFns`, and `muiFilter` for the exact unions and callback props. `MRT_FilterFns` is exported for reuse. The Column Filtering and Global Filtering guides at `/docs/guides/column-filtering` and `/docs/guides/global-filtering` list the related table, column, and state options, and `/docs/examples/customize-filter-variants`, `customize-filter-modes`, `enable-filter-facet-values`, and `alternate-column-filtering` are runnable examples.
|