@mini_7/material-react-table-mcp 4.0.0
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 +68 -0
- package/data/MIGRATION.md +136 -0
- package/data/api.json +5379 -0
- package/data/examples/advanced.tsx +309 -0
- package/data/examples/aggregation-and-grouping.tsx +153 -0
- package/data/examples/aggregation-multi.tsx +105 -0
- package/data/examples/alternate-column-filtering.tsx +49 -0
- package/data/examples/alternate-detail-panel.tsx +81 -0
- package/data/examples/alternate-pagination.tsx +23 -0
- package/data/examples/basic.tsx +109 -0
- package/data/examples/chart-detail-panel.tsx +89 -0
- package/data/examples/column-actions-space.tsx +44 -0
- package/data/examples/column-alignment.tsx +70 -0
- package/data/examples/custom-column-actions.tsx +109 -0
- package/data/examples/custom-column-filtering-ui.tsx +89 -0
- package/data/examples/custom-headless.tsx +125 -0
- package/data/examples/custom-top-toolbar.tsx +88 -0
- package/data/examples/customize-display-columns.tsx +85 -0
- package/data/examples/customize-filter-components.tsx +101 -0
- package/data/examples/customize-filter-modes.tsx +73 -0
- package/data/examples/customize-filter-variants.tsx +116 -0
- package/data/examples/customize-global-filter-component.tsx +52 -0
- package/data/examples/customize-remove-column-grouping.tsx +94 -0
- package/data/examples/customize-row-selection.tsx +54 -0
- package/data/examples/customize-table-styles.tsx +100 -0
- package/data/examples/disable-column-actions.tsx +37 -0
- package/data/examples/disable-column-hiding.tsx +90 -0
- package/data/examples/disable-density-toggle.tsx +49 -0
- package/data/examples/dynamic-columns.tsx +189 -0
- package/data/examples/editing-crud-cell.tsx +377 -0
- package/data/examples/editing-crud-modal.tsx +370 -0
- package/data/examples/editing-crud-row.tsx +333 -0
- package/data/examples/editing-crud-table.tsx +369 -0
- package/data/examples/editing-crud-tree.tsx +416 -0
- package/data/examples/enable-cell-actions.tsx +76 -0
- package/data/examples/enable-click-to-copy.tsx +39 -0
- package/data/examples/enable-column-grouping.tsx +120 -0
- package/data/examples/enable-column-ordering.tsx +48 -0
- package/data/examples/enable-column-pinning.tsx +69 -0
- package/data/examples/enable-column-resizing.tsx +56 -0
- package/data/examples/enable-column-virtualization.tsx +27 -0
- package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
- package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
- package/data/examples/enable-expanding-tree.tsx +110 -0
- package/data/examples/enable-filter-facet-values.tsx +65 -0
- package/data/examples/enable-row-dragging.tsx +137 -0
- package/data/examples/enable-row-numbers-original.tsx +48 -0
- package/data/examples/enable-row-numbers-static.tsx +48 -0
- package/data/examples/enable-row-ordering.tsx +57 -0
- package/data/examples/enable-row-pinning-select.tsx +76 -0
- package/data/examples/enable-row-pinning-static.tsx +50 -0
- package/data/examples/enable-row-pinning-sticky.tsx +69 -0
- package/data/examples/enable-row-selection.tsx +96 -0
- package/data/examples/enable-row-virtualization.tsx +101 -0
- package/data/examples/enable-sticky-header.tsx +59 -0
- package/data/examples/expanding-tree-expanded.tsx +121 -0
- package/data/examples/expanding-tree-flat-parse.tsx +125 -0
- package/data/examples/expanding-tree-root-expanded.tsx +151 -0
- package/data/examples/export-to-csv.tsx +114 -0
- package/data/examples/export-to-pdf.tsx +104 -0
- package/data/examples/external-toolbar.tsx +108 -0
- package/data/examples/font-awesome-icons.tsx +106 -0
- package/data/examples/infinite-scrolling.tsx +208 -0
- package/data/examples/lazy-detail-panel.tsx +262 -0
- package/data/examples/lazy-sub-rows.tsx +190 -0
- package/data/examples/linear-progress.tsx +66 -0
- package/data/examples/loading.tsx +50 -0
- package/data/examples/localization-i18n-ar.tsx +65 -0
- package/data/examples/localization-i18n-az.tsx +60 -0
- package/data/examples/localization-i18n-bg.tsx +60 -0
- package/data/examples/localization-i18n-cs.tsx +60 -0
- package/data/examples/localization-i18n-da.tsx +60 -0
- package/data/examples/localization-i18n-de.tsx +60 -0
- package/data/examples/localization-i18n-el.tsx +60 -0
- package/data/examples/localization-i18n-en.tsx +60 -0
- package/data/examples/localization-i18n-es.tsx +60 -0
- package/data/examples/localization-i18n-et.tsx +60 -0
- package/data/examples/localization-i18n-fa.tsx +66 -0
- package/data/examples/localization-i18n-fi.tsx +60 -0
- package/data/examples/localization-i18n-fr.tsx +60 -0
- package/data/examples/localization-i18n-he.tsx +66 -0
- package/data/examples/localization-i18n-hr.tsx +60 -0
- package/data/examples/localization-i18n-hu.tsx +60 -0
- package/data/examples/localization-i18n-hy.tsx +65 -0
- package/data/examples/localization-i18n-id.tsx +60 -0
- package/data/examples/localization-i18n-it.tsx +60 -0
- package/data/examples/localization-i18n-ja.tsx +60 -0
- package/data/examples/localization-i18n-ko.tsx +60 -0
- package/data/examples/localization-i18n-nl.tsx +60 -0
- package/data/examples/localization-i18n-no.tsx +60 -0
- package/data/examples/localization-i18n-np.tsx +60 -0
- package/data/examples/localization-i18n-pl.tsx +60 -0
- package/data/examples/localization-i18n-pt-BR.tsx +60 -0
- package/data/examples/localization-i18n-pt.tsx +60 -0
- package/data/examples/localization-i18n-ro.tsx +60 -0
- package/data/examples/localization-i18n-ru.tsx +60 -0
- package/data/examples/localization-i18n-sk.tsx +60 -0
- package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
- package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
- package/data/examples/localization-i18n-sv.tsx +60 -0
- package/data/examples/localization-i18n-tr.tsx +60 -0
- package/data/examples/localization-i18n-uk.tsx +60 -0
- package/data/examples/localization-i18n-vi.tsx +60 -0
- package/data/examples/localization-i18n-zh-hans.tsx +60 -0
- package/data/examples/localization-i18n-zh-hant.tsx +60 -0
- package/data/examples/manual-selection.tsx +105 -0
- package/data/examples/minimal.tsx +78 -0
- package/data/examples/mui-theme.tsx +136 -0
- package/data/examples/multi-sorting.tsx +58 -0
- package/data/examples/persistent-state.tsx +184 -0
- package/data/examples/react-query.tsx +182 -0
- package/data/examples/remote.tsx +150 -0
- package/data/examples/row-actions-buttons.tsx +89 -0
- package/data/examples/row-actions-menu-items.tsx +64 -0
- package/data/examples/single-row-selection.tsx +98 -0
- package/data/examples/virtualized.tsx +138 -0
- package/data/guides/accessibility.md +119 -0
- package/data/guides/aggregation.md +210 -0
- package/data/guides/async-loading.md +132 -0
- package/data/guides/best-practices.md +363 -0
- package/data/guides/cell-actions.md +139 -0
- package/data/guides/click-to-copy.md +67 -0
- package/data/guides/column-actions.md +69 -0
- package/data/guides/column-filtering.md +366 -0
- package/data/guides/column-grouping.md +192 -0
- package/data/guides/column-hiding.md +133 -0
- package/data/guides/column-ordering-dnd.md +99 -0
- package/data/guides/column-pinning.md +72 -0
- package/data/guides/column-resizing.md +157 -0
- package/data/guides/column-size.md +162 -0
- package/data/guides/customize-components.md +395 -0
- package/data/guides/customize-icons.md +35 -0
- package/data/guides/data-columns.md +292 -0
- package/data/guides/density-toggle.md +46 -0
- package/data/guides/detail-panel.md +195 -0
- package/data/guides/display-columns.md +135 -0
- package/data/guides/editing.md +367 -0
- package/data/guides/expanding-sub-rows.md +194 -0
- package/data/guides/full-screen-toggle.md +63 -0
- package/data/guides/global-filtering.md +237 -0
- package/data/guides/localization.md +57 -0
- package/data/guides/memoization.md +157 -0
- package/data/guides/pagination.md +171 -0
- package/data/guides/row-actions.md +116 -0
- package/data/guides/row-numbers.md +24 -0
- package/data/guides/row-ordering-dnd.md +51 -0
- package/data/guides/row-pinning.md +96 -0
- package/data/guides/row-selection.md +237 -0
- package/data/guides/sorting.md +190 -0
- package/data/guides/state-management.md +165 -0
- package/data/guides/sticky-header.md +41 -0
- package/data/guides/table-event-listeners.md +103 -0
- package/data/guides/toolbar-customization.md +251 -0
- package/data/guides/virtualization.md +183 -0
- package/data/index.json +1930 -0
- package/data/reference/mrt-components.md +183 -0
- package/data/reference/mrt-hooks.md +125 -0
- package/data/skills/composable-components/SKILL.md +189 -0
- package/data/skills/customization/SKILL.md +190 -0
- package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
- package/data/skills/editing/SKILL.md +243 -0
- package/data/skills/filtering/SKILL.md +213 -0
- package/data/skills/getting-started/SKILL.md +213 -0
- package/data/skills/localization/SKILL.md +182 -0
- package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
- package/data/skills/state-and-server-data/SKILL.md +200 -0
- package/data/skills/virtualization/SKILL.md +203 -0
- package/dist/data.js +137 -0
- package/dist/index.js +232 -0
- package/package.json +50 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
## Column Filtering Feature Guide
|
|
2
|
+
|
|
3
|
+
Filtering is one of the most powerful features of Material React Table and is enabled by default. There is a lot of flexibility and customization available here. Whether you want to customize the powerful client-side filtering already built in or implement your own [server-side filtering](#manual-server-side-column-filtering), Material React Table has got you covered.
|
|
4
|
+
|
|
5
|
+
### Relevant Table Options
|
|
6
|
+
|
|
7
|
+
Relevant table options (get_mrt_api has full details):
|
|
8
|
+
|
|
9
|
+
- `columnFilterModeOptions` - type `Array<MRT_FilterOption | string> | null` - Specify which filter modes are available for every column. Optionally specify this per column as a column option.
|
|
10
|
+
- `enableColumnFilterModes` - type `boolean` - default `false`
|
|
11
|
+
- `enableColumnFilters` - type `boolean` - default `true`
|
|
12
|
+
- `enableFacetedValues` - type `boolean` - default `true` - Enable or disable the calculation of faceted values. Facet values are a list of all unique values in a column. These are useful for advanced filtering components with selection, autocomplete, etc.
|
|
13
|
+
- `enableFilterMatchHighlighting` - type `boolean` - default `true` - Enable or disable highlighting text that matches the filter in the table cells.
|
|
14
|
+
- `enableFilters` - type `boolean` - default `true` - Enable or disable both the global and column filters.
|
|
15
|
+
- `filterFns` - type `Record<string, FilterFn>` - This option allows you to define custom filter functions that can be referenced in a column's filterFn option by their key
|
|
16
|
+
- `filterFromLeafRows` - type `boolean` - default `false`
|
|
17
|
+
- `manualFiltering` - type `boolean` - Disables the getFilteredRowModel from being used to filter data. This may be useful if your table needs to dynamically support both client-side and server-side filtering.
|
|
18
|
+
- `maxLeafRowFilterDepth` - type `number` - default `100` - Set a maximum number leaf row depth that will be filtered. Preserve child rows of filtered rows by setting this to "0"
|
|
19
|
+
- `muiFilterAutocompleteProps` - type `AutocompleteProps | ({ column, rangeFilterIndex, table }) => AutocompleteProps`
|
|
20
|
+
- `muiFilterCheckboxProps` - type `CheckboxProps | ({ column, table}) => CheckboxProps`
|
|
21
|
+
- `muiFilterDatePickerProps` - type `DatePickerProps | ({ column, rangeFilterIndex, table }) => DatePickerProps`
|
|
22
|
+
- `muiFilterDateTimePickerProps` - type `DateTimePickerProps | ({ column, rangeFilterIndex, table }) => DateTimePickerProps`
|
|
23
|
+
- `muiFilterSliderProps` - type `SliderProps | ({ column, table}) => SliderProps`
|
|
24
|
+
- `muiFilterTextFieldProps` - type `TextFieldProps | ({ table, column, rangeFilterIndex}) => TextFieldProps`
|
|
25
|
+
- `muiFilterTimePickerProps` - type `TimePickerProps | ({ column, rangeFilterIndex, table }) => TimePickerProps`
|
|
26
|
+
- `onColumnFilterFnsChange` - type `OnChangeFn<{ [key: string]: MRT_FilterOption }>`
|
|
27
|
+
- `onColumnFiltersChange` - type `OnChangeFn<ColumnFiltersState>` - If provided, this function will be called with an updaterFn when state.columnFilters changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
|
|
28
|
+
- `onShowColumnFiltersChange` - type `OnChangeFn<boolean>`
|
|
29
|
+
- `renderColumnFilterModeMenuItems` - type `({ column, internalFilterOptions, onSelectFilterMode, table }) => ReactNode[]`
|
|
30
|
+
|
|
31
|
+
### Relevant Column Options
|
|
32
|
+
|
|
33
|
+
Relevant column options (get_mrt_api has full details):
|
|
34
|
+
|
|
35
|
+
- `columnFilterModeOptions` - type `Array<string>`
|
|
36
|
+
- `enableColumnFilter` - type `boolean` - Enable or disable column filtering for this column. Filter will not be shown if disabled.
|
|
37
|
+
- `enableColumnFilterModes` - type `boolean` - Enable column filtering modes for this column.
|
|
38
|
+
- `enableFilterMatchHighlighting` - type `boolean` - Enable or disable filter match highlighting for this column.
|
|
39
|
+
- `Filter` - type `({ column, header, table }) => ReactNode` - Define a custom filter component in a column.
|
|
40
|
+
- `filterFn` - type `MRT_FilterFn` - default `'fuzzy'`
|
|
41
|
+
- `filterSelectOptions` - type `Array<string | { label: string; value: string }>`
|
|
42
|
+
- `filterVariant` - type `'text' | 'select' | 'multi-select' | 'range' | 'range-slider' | 'checkbox' | 'autocomplete' | 'date' | 'date-range' | 'datetime' | 'datetime-range' | 'time' | 'time-range'` - default `'text'` - Specify whether the filter should be a text input or a select input, or other type of pre-built input.
|
|
43
|
+
- `muiFilterAutocompleteProps` - type `AutocompleteProps | ({ column, rangeFilterIndex, table }) => AutocompleteProps`
|
|
44
|
+
- `muiFilterCheckboxProps` - type `CheckboxProps | ({ column, table }) => CheckboxProps`
|
|
45
|
+
- `muiFilterDatePickerProps` - type `DatePickerProps | ({ column, rangeFilterIndex, table }) => DatePickerProps`
|
|
46
|
+
- `muiFilterDateTimePickerProps` - type `DateTimePickerProps | ({ column, rangeFilterIndex, table }) => DateTimePickerProps`
|
|
47
|
+
- `muiFilterSliderProps` - type `SliderProps | ({ column, table}) => SliderProps`
|
|
48
|
+
- `muiFilterTextFieldProps` - type `TextFieldProps | ({ column, rangeFilterIndex, table }) => TextFieldProps`
|
|
49
|
+
- `muiFilterTimePickerProps` - type `TimePickerProps | ({ column, rangeFilterIndex, table }) => TimePickerProps`
|
|
50
|
+
- `renderColumnFilterModeMenuItems`
|
|
51
|
+
|
|
52
|
+
### Relevant State Options
|
|
53
|
+
|
|
54
|
+
Relevant state options (get_mrt_api has full details):
|
|
55
|
+
|
|
56
|
+
- `columnFilterFns` - type `{ [key: string]: MRT_FilterFn }`
|
|
57
|
+
- `columnFilters` - type `Array<{id: string, value: unknown}>` - default `{}` - an array of objects with id and value properties, representing the current filter values for each column
|
|
58
|
+
- `showColumnFilters` - type `boolean` - default `false`
|
|
59
|
+
|
|
60
|
+
### Disable Filtering Features
|
|
61
|
+
|
|
62
|
+
Various subsets of filtering features can be disabled. If you want to disable filtering completely, you can set the `enableColumnFilters` table option to `false` to remove all filters from each column. Alternatively, `enableColumnFilter` can be set to `false` for individual columns.
|
|
63
|
+
|
|
64
|
+
`enableFilters` can be set to `false` to disable both column filters and the global search filter.
|
|
65
|
+
|
|
66
|
+
### Filter Variants
|
|
67
|
+
|
|
68
|
+
Material React Table has several built-in filter variants for advanced filtering. These can be specified on a per-column basis using the `filterVariant` option. The following variants are available:
|
|
69
|
+
|
|
70
|
+
- `'text'` - shows the default text field
|
|
71
|
+
- `'autocomplete'` - shows an autocomplete text field with the options from faceted values or specified in `filterSelectOptions` array.
|
|
72
|
+
- `'select'` - shows a select dropdown with the options from faceted values or specified in `filterSelectOptions` array.
|
|
73
|
+
- `'multi-select'` - shows a select dropdown with the options from faceted values or specified in `filterSelectOptions` and allows multiple selections with checkboxes
|
|
74
|
+
- `'range'` - shows min and max text fields for filtering a range of values
|
|
75
|
+
- `'range-slider'` - shows a slider for filtering a range of values
|
|
76
|
+
- `'date'` - shows a date picker for filtering by date values
|
|
77
|
+
- `'datetime'` - shows a date and time picker for filtering by date and time values
|
|
78
|
+
- `'date-range'` - shows a date range picker for filtering by date ranges
|
|
79
|
+
- `'datetime-range'` - shows a date and time range picker for filtering by date and time ranges
|
|
80
|
+
- `'time'` - shows a time picker for filtering by time values
|
|
81
|
+
- `'time-range'` - shows a time range picker for filtering by time ranges
|
|
82
|
+
- `'checkbox'` - shows a checkbox for filtering by `'true'` or `'false'` values
|
|
83
|
+
|
|
84
|
+
> `'autocomplete'`, `'date'`, and `'date-range'`, variants are new in v2.0.0
|
|
85
|
+
>
|
|
86
|
+
> `datetime`, `datetime-range`, `time`, and `time-range` variants are new in v2.4.0
|
|
87
|
+
|
|
88
|
+
> Live example: `customize-filter-variants` (call get_mrt_example with that id).
|
|
89
|
+
|
|
90
|
+
#### Faceted Values for Filter Variants
|
|
91
|
+
|
|
92
|
+
Faceted values are a list of unique values for a column that gets generated under the hood from table data when the `enableFacetedValues` table option is set to `true`. These values can be used to populate the select dropdowns for the `'select'` and `'multi-select'` filter variants, or the min and max values for the `'range-slider'` variant. This means that you no longer need to manually specify the `filterSelectOptions` table option for these variants manually, especially if you are using client-side filtering.
|
|
93
|
+
|
|
94
|
+
> Live example: `enable-filter-facet-values` (call get_mrt_example with that id).
|
|
95
|
+
|
|
96
|
+
#### Custom Faceted Values
|
|
97
|
+
|
|
98
|
+
If you are using server-side pagination and filtering, you can still customize the faceted values output with the `getFacetedUniqueValues` and `getFacetedMinMaxValues` props.
|
|
99
|
+
|
|
100
|
+
```jsx
|
|
101
|
+
const table = useMaterialReactTable({
|
|
102
|
+
columns,
|
|
103
|
+
data,
|
|
104
|
+
enableFacetedValues: true,
|
|
105
|
+
//if using server-side pagination and filtering
|
|
106
|
+
getFacetedMinMaxValues: (table) => {
|
|
107
|
+
//fetch min and max values from server
|
|
108
|
+
return [minValue, maxValue];
|
|
109
|
+
},
|
|
110
|
+
//if using server-side filtering
|
|
111
|
+
getFacetedUniqueValues: (table) => {
|
|
112
|
+
const uniqueValueMap = new Map<string, number>();
|
|
113
|
+
//fetch unique values from server, ideally including the count of each unique value
|
|
114
|
+
return uniqueValueMap;
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Column Filter Display Modes
|
|
120
|
+
|
|
121
|
+
By default, column filters inputs show below the column header. You can switch to a more "excel-like" UI by setting the `columnFilterDisplayMode` table option to `'popover'`. This will show a filter icon in the column header that can be clicked to open a popover with the filter input.
|
|
122
|
+
|
|
123
|
+
```jsx
|
|
124
|
+
const table = useMaterialReactTable({
|
|
125
|
+
columns,
|
|
126
|
+
data,
|
|
127
|
+
columnFilterDisplayMode: 'popover', //filter inputs will show in a popover (like excel)
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Alternatively, if you want to render your own column filter UI in a separate sidebar, but still want to use the built-in filtering functionality, you can set the `columnFilterDisplayMode` table option to `'custom'`.
|
|
132
|
+
|
|
133
|
+
```jsx
|
|
134
|
+
const table = useMaterialReactTable({
|
|
135
|
+
columns,
|
|
136
|
+
data,
|
|
137
|
+
columnFilterDisplayMode: 'custom', //render your own column filter UI (e.g. in a sidebar)
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
> Live example: `alternate-column-filtering` (call get_mrt_example with that id).
|
|
142
|
+
|
|
143
|
+
### Custom Filter Functions
|
|
144
|
+
|
|
145
|
+
You can specify either a pre-built filterFn that comes with Material React Table or pass in your own custom filter functions.
|
|
146
|
+
|
|
147
|
+
#### Custom Filter Functions Per Column
|
|
148
|
+
|
|
149
|
+
By default, Material React Table uses a `fuzzy` filtering algorithm based on the popular `match-sorter` [library from Kent C. Dodds](https://www.npmjs.com/package/match-sorter). However, Material React Table also comes with numerous other filter functions that you can specify per column in the `filterFn` column options.
|
|
150
|
+
|
|
151
|
+
##### Pre-built MRT Filter Functions
|
|
152
|
+
|
|
153
|
+
> Pre-built filter functions from Material React Table include `between`, `betweenInclusive`, `contains`, `empty`, `endsWith`, `equals`, `fuzzy`, `greaterThan`, `greaterThanOrEqualTo`, `lessThan`, `lessThanOrEqualTo`, `notEmpty`, `notEquals`, and `startsWith`. View these algorithms [here](https://github.com/gyminii/material-react-table/blob/v4/packages/material-react-table/src/fns/filterFns.ts)
|
|
154
|
+
|
|
155
|
+
##### Pre-built TanStack Table Filter Functions
|
|
156
|
+
|
|
157
|
+
> Pre-built filter functions from TanStack Table include `includesString`, `includesStringSensitive`, `equalsString`, `equalsStringSensitive`, `arrIncludes`, `arrIncludesAll`, `arrIncludesSome`, `weakEquals`, and `inNumberRange`. View more information about these algorithms in the [TanStack Table Filter docs](https://tanstack.com/table/v9/docs/framework/react/guide/column-filtering).
|
|
158
|
+
|
|
159
|
+
You can specify either a pre-built filter function, from Material React Table or TanStack Table, or you can even specify _your own custom filter function_ in the `filterFn` column option.
|
|
160
|
+
|
|
161
|
+
```jsx
|
|
162
|
+
const columns = [
|
|
163
|
+
{
|
|
164
|
+
accessorKey: 'firstName',
|
|
165
|
+
header: 'First Name',
|
|
166
|
+
// using a prebuilt filter function from Material React Table
|
|
167
|
+
filterFn: 'startsWith',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
accessorKey: 'middleName',
|
|
171
|
+
header: 'Middle Name',
|
|
172
|
+
// using a prebuilt filter function from TanStack Table
|
|
173
|
+
filterFn: 'includesStringSensitive',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
accessorKey: 'lastName',
|
|
177
|
+
header: 'Last Name',
|
|
178
|
+
// custom filter function
|
|
179
|
+
filterFn: (row, id, filterValue) =>
|
|
180
|
+
row.getValue(id).startsWith(filterValue),
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
If you provide a custom filter function, it must have the following signature:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
(row: Row<TData>, id: string, filterValue: string | number) => boolean;
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
This function will be used to filter 1 row at a time and should return a `boolean` indicating whether or not that row passes the filter.
|
|
192
|
+
|
|
193
|
+
#### Add Custom Filter Functions
|
|
194
|
+
|
|
195
|
+
You can add custom filter functions to the `filterFns` table option. These will be available to all columns to use. The `filterFn` table option on a column will override any filter function with the same name in the `filterFns` table option.
|
|
196
|
+
|
|
197
|
+
```jsx
|
|
198
|
+
const columns = [
|
|
199
|
+
{
|
|
200
|
+
accessorKey: 'name',
|
|
201
|
+
header: 'Name',
|
|
202
|
+
filterFn: 'customFilterFn',
|
|
203
|
+
},
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
const table = useMaterialReactTable({
|
|
207
|
+
columns,
|
|
208
|
+
data,
|
|
209
|
+
filterFns: {
|
|
210
|
+
customFilterFn: (row, id, filterValue) => {
|
|
211
|
+
return row.customField === value;
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
});
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### Filter Modes
|
|
218
|
+
|
|
219
|
+
#### Enable Column Filter Modes (Filter Switching)
|
|
220
|
+
|
|
221
|
+
If you want to let the user switch between multiple different filter modes from a drop-down menu on the Filter Textfield, you can enable that with the `enableColumnFilterModes` table option or column option. This will enable the filter icon in the filter text field to open a drop-down menu with the available filter modes when clicked.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
const table = useMaterialReactTable({
|
|
225
|
+
columns,
|
|
226
|
+
data,
|
|
227
|
+
enableColumnFilterModes: true,
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### Customize Filter Modes
|
|
232
|
+
|
|
233
|
+
You can narrow down the available filter mode options by setting the `columnFilterModeOptions` table option or a column specific `columnFilterModeOptions` option.
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
const columns = [
|
|
237
|
+
{
|
|
238
|
+
accessorKey: 'firstName',
|
|
239
|
+
header: 'First Name',
|
|
240
|
+
columnFilterModeOptions: ['fuzzy', 'contains', 'startsWith'],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
accessorKey: 'age',
|
|
244
|
+
header: 'Age',
|
|
245
|
+
columnFilterModeOptions: ['between', 'lessThan', 'greaterThan'],
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### Render Custom Filter Mode Menu
|
|
251
|
+
|
|
252
|
+
You can also render custom menu items in the filter mode drop-down menu by setting the `renderColumnFilterModeMenuItems` table option or column option. This option is a function that takes in the column and returns an array of `MenuItem` components. This is useful if you want to add custom filter modes that are not included in Material React Table, or if you just want to render the menu in your own custom way
|
|
253
|
+
|
|
254
|
+
```jsx
|
|
255
|
+
const columns = [
|
|
256
|
+
{
|
|
257
|
+
accessorKey: 'firstName',
|
|
258
|
+
header: 'First Name',
|
|
259
|
+
renderColumnFilterModeMenuItems: ({ column, onSelectFilterMode }) => [
|
|
260
|
+
<MenuItem
|
|
261
|
+
key="startsWith"
|
|
262
|
+
onClick={() => onSelectFilterMode('startsWith')}
|
|
263
|
+
>
|
|
264
|
+
Start With
|
|
265
|
+
</MenuItem>,
|
|
266
|
+
<MenuItem
|
|
267
|
+
key="endsWith"
|
|
268
|
+
onClick={() => onSelectFilterMode('yourCustomFilterFn')}
|
|
269
|
+
>
|
|
270
|
+
Your Custom Filter Fn
|
|
271
|
+
</MenuItem>,
|
|
272
|
+
],
|
|
273
|
+
},
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
const table = useMaterialReactTable({
|
|
277
|
+
columns,
|
|
278
|
+
data,
|
|
279
|
+
enableColumnFilterModes: true,
|
|
280
|
+
// renderColumnFilterModeMenuItems could go here if you want to apply to all columns
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return <MaterialReactTable table={table} />;
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
> Live example: `customize-filter-modes` (call get_mrt_example with that id).
|
|
287
|
+
|
|
288
|
+
### Expanded Leaf Row Filtering Options
|
|
289
|
+
|
|
290
|
+
If you are using the filtering features along-side either the [grouping](/docs/guides/aggregation-and-grouping) or [expanding](/docs/guides/expanding-sub-rows) features, then there are a few behaviors and customizations you should be aware of.
|
|
291
|
+
|
|
292
|
+
Check out the [Expanded Leaf Row Filtering Behavior docs](/docs/guides/expanding-sub-rows#expanded-leaf-row-filtering-behavior) to learn more about the `filterFromLeafRows` and `maxLeafRowFilterDepth` props.
|
|
293
|
+
|
|
294
|
+
### Manual Server-Side Column Filtering
|
|
295
|
+
|
|
296
|
+
A very common use case when you have a lot of data is to filter the data on the server, instead of client-side. In this case, you will want to set the `manualFiltering` table option to `true` and manage the `columnFilters` state yourself like so (can work in conjunction with [manual global filtering](/docs/guides/global-filtering#manual-server-side-global-filtering)).
|
|
297
|
+
|
|
298
|
+
```jsx
|
|
299
|
+
// You can manage and have control over the columnFilters state yourself
|
|
300
|
+
const [columnFilters, setColumnFilters] = useState([]);
|
|
301
|
+
const [data, setData] = useState([]); //data will get updated after re-fetching
|
|
302
|
+
|
|
303
|
+
useEffect(() => {
|
|
304
|
+
const fetchData = async () => {
|
|
305
|
+
// send api requests when columnFilters state changes
|
|
306
|
+
const filteredData = await fetch();
|
|
307
|
+
setData([...filteredData]);
|
|
308
|
+
};
|
|
309
|
+
}, [columnFilters]);
|
|
310
|
+
|
|
311
|
+
const table = useMaterialReactTable({
|
|
312
|
+
columns,
|
|
313
|
+
data, // this will already be filtered on the server
|
|
314
|
+
manualFiltering: true, //turn off client-side filtering
|
|
315
|
+
onColumnFiltersChange: setColumnFilters, //hoist internal columnFilters state to your state
|
|
316
|
+
state: { columnFilters }, //pass in your own managed columnFilters state
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
return <MaterialReactTable table={table} />;
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
> Specifying `manualFiltering` turns off all client-side filtering and assumes that the `data` you pass to `<MaterialReactTable />` is already filtered.
|
|
323
|
+
|
|
324
|
+
See either the [React Query](/docs/examples/react-query) or [useEffect fetching](/docs/examples/remote) examples to see fully server-side **filtering**, pagination, and sorting in action.
|
|
325
|
+
|
|
326
|
+
### Customize Material UI Filter components
|
|
327
|
+
|
|
328
|
+
You can customize the Material UI filter components by setting the `muiFilterTextFieldProps` table option or column option.
|
|
329
|
+
|
|
330
|
+
You can also turn a filter textfield into a select dropdown by setting the `filterSelectOptions` table option or column option.
|
|
331
|
+
|
|
332
|
+
> Live example: `customize-filter-components` (call get_mrt_example with that id).
|
|
333
|
+
|
|
334
|
+
### Custom Filter Components
|
|
335
|
+
|
|
336
|
+
If you need custom filter components that are much more complex than text-boxes and dropdowns, you can create and pass in your own filter components using the `Filter` column option.
|
|
337
|
+
|
|
338
|
+
### Filter Match Highlighting
|
|
339
|
+
|
|
340
|
+
Filter Match Highlighting is a new featured enabled by default that will highlight text in the table body cells that matches the current filter query with a shade of the `theme.palette.warning.main` color.
|
|
341
|
+
|
|
342
|
+
Filter Match Highlighting will only work on columns with the default `text` filter variant. Also, if you are using a custom `Cell` render override for a column, you will need to use the `renderedCellValue` table option instead of `cell.getValue()` in order to preserve the filter match highlighting.
|
|
343
|
+
|
|
344
|
+
```jsx
|
|
345
|
+
const columns = [
|
|
346
|
+
{
|
|
347
|
+
accessorKey: 'name',
|
|
348
|
+
header: 'Name',
|
|
349
|
+
Cell: ({ renderedCellValue }) => <span>{renderedCellValue}</span>, // use renderedCellValue instead of cell.getValue()
|
|
350
|
+
},
|
|
351
|
+
];
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
#### Disable Filter Match Highlighting
|
|
355
|
+
|
|
356
|
+
This feature can be disabled by setting the `enableFilterMatchHighlighting` table option to `false`.
|
|
357
|
+
|
|
358
|
+
```jsx
|
|
359
|
+
const table = useMaterialReactTable({
|
|
360
|
+
columns,
|
|
361
|
+
data,
|
|
362
|
+
enableFilterMatchHighlighting: false,
|
|
363
|
+
});
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-filtering-examples)**
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
## Column Grouping Feature Guide
|
|
2
|
+
|
|
3
|
+
Material React Table has built-in column grouping features. There are options for both automatic client-side grouping as well as manual server-side grouping. This guide will walk you through the different options and how to use and customize them.
|
|
4
|
+
|
|
5
|
+
### Relevant Table Options
|
|
6
|
+
|
|
7
|
+
Relevant table options (get_mrt_api has full details):
|
|
8
|
+
|
|
9
|
+
- `enableExpandAll` - type `boolean` - default `true`
|
|
10
|
+
- `enableGrouping` - type `boolean`
|
|
11
|
+
- `groupedColumnMode` - type `false | 'reorder' | 'remove'` - default `reorder` - Grouping columns are automatically reordered by default to the start of the columns list. If you would rather remove them or leave them as-is, set the appropriate mode here.
|
|
12
|
+
- `manualGrouping` - type `boolean` - Enables manual grouping. If this option is set to true, the table will not automatically group rows using getGroupedRowModel() and instead will expect you to manually group the rows before passing them to the table. This is useful if you are doing server-side grouping and aggregation.
|
|
13
|
+
- `muiToolbarAlertBannerChipProps` - type `ChipProps| ({ table }} => ChipProps`
|
|
14
|
+
- `onGroupingChange` - type `OnChangeFn<GroupingState>` - If this function is provided, it will be called when the grouping state changes and you will be expected to manage the state yourself. You can pass the managed state back to the table via the tableOptions.state.grouping option.
|
|
15
|
+
- `positionToolbarAlertBanner` - type `'bottom' | 'top' | 'none'` - default `'top'`
|
|
16
|
+
- `renderToolbarAlertBannerContent` - type `({ table, groupedAlert, selectedAlert }) => ReactNode`
|
|
17
|
+
|
|
18
|
+
### Relevant Column Options
|
|
19
|
+
|
|
20
|
+
Relevant column options (get_mrt_api has full details):
|
|
21
|
+
|
|
22
|
+
- `AggregatedCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for an aggregated cell.
|
|
23
|
+
- `enableGrouping` - type `boolean`
|
|
24
|
+
- `GroupedCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for a grouped cell.
|
|
25
|
+
- `PlaceholderCell` - type `({ cell, column, row, table }) => ReactNode` - Define a custom cell render for a placeholder cell.
|
|
26
|
+
|
|
27
|
+
### Relevant State
|
|
28
|
+
|
|
29
|
+
Relevant state options (get_mrt_api has full details):
|
|
30
|
+
|
|
31
|
+
- `expanded` - type `Record<string, boolean> | boolean` - default `{}`
|
|
32
|
+
- `grouping` - type `Array<string>` - default `[]`
|
|
33
|
+
|
|
34
|
+
### Enable Grouping
|
|
35
|
+
|
|
36
|
+
To enable grouping, set the `enableGrouping` table option to `true`. This will both add a drag handle button so that columns can be dragged to the dropzone to be grouped and will add an entry column actions menu to group or ungroup a column.
|
|
37
|
+
|
|
38
|
+
```jsx
|
|
39
|
+
const table = useMaterialReactTable({
|
|
40
|
+
columns,
|
|
41
|
+
data,
|
|
42
|
+
enableGrouping: true,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Grouped Column Mode
|
|
47
|
+
|
|
48
|
+
> New in v2.5.0, The `"remove"` columnGroupMode now has an official UI implementation
|
|
49
|
+
|
|
50
|
+
The `groupedColumnMode` table option controls how grouped columns are displayed once a column has been grouped. There are three options:
|
|
51
|
+
|
|
52
|
+
1. `"reorder"` (default) - Grouped columns will be displayed as the first columns in the table, followed by the 'mrt-row-expand' display column, followed by the remaining columns in their original order.
|
|
53
|
+
2. `"remove"` - Grouped columns will be removed from the table and only their aggregate values will be displayed alongside the expand button in the 'mrt-row-expand' display column, followed by the remaining columns in their original order.
|
|
54
|
+
3. `false` - Grouping columns will have no effect on the column order. The 'mrt-row-expand' display column will be displayed as the first column in the table, followed by the remaining columns in their original order.
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
const table = useMaterialReactTable({
|
|
58
|
+
columns,
|
|
59
|
+
data,
|
|
60
|
+
enableGrouping: true,
|
|
61
|
+
groupedColumnMode: 'remove', //instead of default "reorder"
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
> Live example: `enable-column-grouping` (call get_mrt_example with that id).
|
|
66
|
+
|
|
67
|
+
#### Disable Grouping Per Column
|
|
68
|
+
|
|
69
|
+
```jsx
|
|
70
|
+
const columns = [
|
|
71
|
+
{
|
|
72
|
+
accessorKey: 'name',
|
|
73
|
+
header: 'Name',
|
|
74
|
+
enableGrouping: false, // disable grouping for this column
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
accessorKey: 'age',
|
|
78
|
+
header: 'Age',
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const table = useMaterialReactTable({
|
|
83
|
+
columns,
|
|
84
|
+
data,
|
|
85
|
+
enableGrouping: true,
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
return <MaterialReactTable table={table} />;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### Hide Drag Buttons for Grouping
|
|
92
|
+
|
|
93
|
+
If you do not want the drag buttons that come with the grouping feature, you can independently disable them without disabling the grouping feature entirely by setting the `enableColumnDragging` table option to `false`.
|
|
94
|
+
|
|
95
|
+
```jsx
|
|
96
|
+
const table = useMaterialReactTable({
|
|
97
|
+
columns,
|
|
98
|
+
data,
|
|
99
|
+
enableGrouping: true,
|
|
100
|
+
enableColumnDragging: false, //do not show drag handle buttons, but still show grouping options in column actions menu
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return <MaterialReactTable table={table} />;
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Group Columns by Default
|
|
107
|
+
|
|
108
|
+
If you want columns to be grouped by default, you can set the `grouping` state in either the `initialState` or `state` table option.
|
|
109
|
+
|
|
110
|
+
```jsx
|
|
111
|
+
const table = useMaterialReactTable({
|
|
112
|
+
columns,
|
|
113
|
+
data,
|
|
114
|
+
enableGrouping: true,
|
|
115
|
+
initialState: { grouping: ['location', 'department'] }, //group by location and department by default
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return <MaterialReactTable table={table} />;
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Expand Grouped Rows by Default
|
|
122
|
+
|
|
123
|
+
In addition to grouping columns by default, you may also want those grouped rows to be expanded and visible by default, too. You can do this by setting the `expanded` state to `true` in either the `initialState` or `state` table option.
|
|
124
|
+
|
|
125
|
+
```jsx
|
|
126
|
+
const table = useMaterialReactTable({
|
|
127
|
+
columns,
|
|
128
|
+
data,
|
|
129
|
+
enableGrouping: true,
|
|
130
|
+
initialState: {
|
|
131
|
+
grouping: ['location', 'department'], //group by location and department by default and expand grouped rows
|
|
132
|
+
expanded: true, //show grouped rows by default
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return <MaterialReactTable table={table} />;
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Customize Expand Column
|
|
140
|
+
|
|
141
|
+
You can customize the expand column by using the `displayColumnDefOptions` table option.
|
|
142
|
+
|
|
143
|
+
```jsx
|
|
144
|
+
const table = useMaterialReactTable({
|
|
145
|
+
columns,
|
|
146
|
+
data,
|
|
147
|
+
enableGrouping: true,
|
|
148
|
+
displayColumnDefOptions: {
|
|
149
|
+
'mrt-row-expand': {
|
|
150
|
+
size: 120, //make the expand column wider
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Going further, you can completely overhaul how the expand column renders using custom `Cell` and `Header` renders here for advanced use cases.
|
|
157
|
+
|
|
158
|
+
```jsx
|
|
159
|
+
const table = useMaterialReactTable({
|
|
160
|
+
columns,
|
|
161
|
+
data,
|
|
162
|
+
enableGrouping: true,
|
|
163
|
+
displayColumnDefOptions: {
|
|
164
|
+
'mrt-row-expand': {
|
|
165
|
+
Cell: ({ row, table }) => {
|
|
166
|
+
return (
|
|
167
|
+
<>
|
|
168
|
+
<MRT_ExpandButton row={row} table={table} />
|
|
169
|
+
{/*custom content*/}
|
|
170
|
+
</>
|
|
171
|
+
);
|
|
172
|
+
},
|
|
173
|
+
Header: ({ table }) => {
|
|
174
|
+
return (
|
|
175
|
+
<>
|
|
176
|
+
<MRT_ExpandAllButton table={table} />
|
|
177
|
+
{/*custom content*/}
|
|
178
|
+
</>
|
|
179
|
+
);
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
> Live example: `customize-remove-column-grouping` (call get_mrt_example with that id).
|
|
187
|
+
|
|
188
|
+
### Manual Grouping
|
|
189
|
+
|
|
190
|
+
Manual Grouping means that the `data` that you pass to the table is already grouped and aggregated, and you do not want Material React Table to do any of the grouping or aggregation for you. This is useful if you are using a backend API to do the grouping and aggregation for you, and you just want to display the results. However, you will need to put your data in the specific format that the `expanding` features understand.
|
|
191
|
+
|
|
192
|
+
> Learn more about [Expanding Sub Rows](/docs/guides/expanding-sub-rows) and [Aggregation](/docs/guides/aggregation) Features in their own dedicated guides.
|