@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.
Files changed (170) hide show
  1. package/README.md +68 -0
  2. package/data/MIGRATION.md +136 -0
  3. package/data/api.json +5379 -0
  4. package/data/examples/advanced.tsx +309 -0
  5. package/data/examples/aggregation-and-grouping.tsx +153 -0
  6. package/data/examples/aggregation-multi.tsx +105 -0
  7. package/data/examples/alternate-column-filtering.tsx +49 -0
  8. package/data/examples/alternate-detail-panel.tsx +81 -0
  9. package/data/examples/alternate-pagination.tsx +23 -0
  10. package/data/examples/basic.tsx +109 -0
  11. package/data/examples/chart-detail-panel.tsx +89 -0
  12. package/data/examples/column-actions-space.tsx +44 -0
  13. package/data/examples/column-alignment.tsx +70 -0
  14. package/data/examples/custom-column-actions.tsx +109 -0
  15. package/data/examples/custom-column-filtering-ui.tsx +89 -0
  16. package/data/examples/custom-headless.tsx +125 -0
  17. package/data/examples/custom-top-toolbar.tsx +88 -0
  18. package/data/examples/customize-display-columns.tsx +85 -0
  19. package/data/examples/customize-filter-components.tsx +101 -0
  20. package/data/examples/customize-filter-modes.tsx +73 -0
  21. package/data/examples/customize-filter-variants.tsx +116 -0
  22. package/data/examples/customize-global-filter-component.tsx +52 -0
  23. package/data/examples/customize-remove-column-grouping.tsx +94 -0
  24. package/data/examples/customize-row-selection.tsx +54 -0
  25. package/data/examples/customize-table-styles.tsx +100 -0
  26. package/data/examples/disable-column-actions.tsx +37 -0
  27. package/data/examples/disable-column-hiding.tsx +90 -0
  28. package/data/examples/disable-density-toggle.tsx +49 -0
  29. package/data/examples/dynamic-columns.tsx +189 -0
  30. package/data/examples/editing-crud-cell.tsx +377 -0
  31. package/data/examples/editing-crud-modal.tsx +370 -0
  32. package/data/examples/editing-crud-row.tsx +333 -0
  33. package/data/examples/editing-crud-table.tsx +369 -0
  34. package/data/examples/editing-crud-tree.tsx +416 -0
  35. package/data/examples/enable-cell-actions.tsx +76 -0
  36. package/data/examples/enable-click-to-copy.tsx +39 -0
  37. package/data/examples/enable-column-grouping.tsx +120 -0
  38. package/data/examples/enable-column-ordering.tsx +48 -0
  39. package/data/examples/enable-column-pinning.tsx +69 -0
  40. package/data/examples/enable-column-resizing.tsx +56 -0
  41. package/data/examples/enable-column-virtualization.tsx +27 -0
  42. package/data/examples/enable-detail-panel-conditionally.tsx +78 -0
  43. package/data/examples/enable-detail-panel-virtualized.tsx +80 -0
  44. package/data/examples/enable-expanding-tree.tsx +110 -0
  45. package/data/examples/enable-filter-facet-values.tsx +65 -0
  46. package/data/examples/enable-row-dragging.tsx +137 -0
  47. package/data/examples/enable-row-numbers-original.tsx +48 -0
  48. package/data/examples/enable-row-numbers-static.tsx +48 -0
  49. package/data/examples/enable-row-ordering.tsx +57 -0
  50. package/data/examples/enable-row-pinning-select.tsx +76 -0
  51. package/data/examples/enable-row-pinning-static.tsx +50 -0
  52. package/data/examples/enable-row-pinning-sticky.tsx +69 -0
  53. package/data/examples/enable-row-selection.tsx +96 -0
  54. package/data/examples/enable-row-virtualization.tsx +101 -0
  55. package/data/examples/enable-sticky-header.tsx +59 -0
  56. package/data/examples/expanding-tree-expanded.tsx +121 -0
  57. package/data/examples/expanding-tree-flat-parse.tsx +125 -0
  58. package/data/examples/expanding-tree-root-expanded.tsx +151 -0
  59. package/data/examples/export-to-csv.tsx +114 -0
  60. package/data/examples/export-to-pdf.tsx +104 -0
  61. package/data/examples/external-toolbar.tsx +108 -0
  62. package/data/examples/font-awesome-icons.tsx +106 -0
  63. package/data/examples/infinite-scrolling.tsx +208 -0
  64. package/data/examples/lazy-detail-panel.tsx +262 -0
  65. package/data/examples/lazy-sub-rows.tsx +190 -0
  66. package/data/examples/linear-progress.tsx +66 -0
  67. package/data/examples/loading.tsx +50 -0
  68. package/data/examples/localization-i18n-ar.tsx +65 -0
  69. package/data/examples/localization-i18n-az.tsx +60 -0
  70. package/data/examples/localization-i18n-bg.tsx +60 -0
  71. package/data/examples/localization-i18n-cs.tsx +60 -0
  72. package/data/examples/localization-i18n-da.tsx +60 -0
  73. package/data/examples/localization-i18n-de.tsx +60 -0
  74. package/data/examples/localization-i18n-el.tsx +60 -0
  75. package/data/examples/localization-i18n-en.tsx +60 -0
  76. package/data/examples/localization-i18n-es.tsx +60 -0
  77. package/data/examples/localization-i18n-et.tsx +60 -0
  78. package/data/examples/localization-i18n-fa.tsx +66 -0
  79. package/data/examples/localization-i18n-fi.tsx +60 -0
  80. package/data/examples/localization-i18n-fr.tsx +60 -0
  81. package/data/examples/localization-i18n-he.tsx +66 -0
  82. package/data/examples/localization-i18n-hr.tsx +60 -0
  83. package/data/examples/localization-i18n-hu.tsx +60 -0
  84. package/data/examples/localization-i18n-hy.tsx +65 -0
  85. package/data/examples/localization-i18n-id.tsx +60 -0
  86. package/data/examples/localization-i18n-it.tsx +60 -0
  87. package/data/examples/localization-i18n-ja.tsx +60 -0
  88. package/data/examples/localization-i18n-ko.tsx +60 -0
  89. package/data/examples/localization-i18n-nl.tsx +60 -0
  90. package/data/examples/localization-i18n-no.tsx +60 -0
  91. package/data/examples/localization-i18n-np.tsx +60 -0
  92. package/data/examples/localization-i18n-pl.tsx +60 -0
  93. package/data/examples/localization-i18n-pt-BR.tsx +60 -0
  94. package/data/examples/localization-i18n-pt.tsx +60 -0
  95. package/data/examples/localization-i18n-ro.tsx +60 -0
  96. package/data/examples/localization-i18n-ru.tsx +60 -0
  97. package/data/examples/localization-i18n-sk.tsx +60 -0
  98. package/data/examples/localization-i18n-sr-Cyrl-RS.tsx +60 -0
  99. package/data/examples/localization-i18n-sr-Latn-RS.tsx +60 -0
  100. package/data/examples/localization-i18n-sv.tsx +60 -0
  101. package/data/examples/localization-i18n-tr.tsx +60 -0
  102. package/data/examples/localization-i18n-uk.tsx +60 -0
  103. package/data/examples/localization-i18n-vi.tsx +60 -0
  104. package/data/examples/localization-i18n-zh-hans.tsx +60 -0
  105. package/data/examples/localization-i18n-zh-hant.tsx +60 -0
  106. package/data/examples/manual-selection.tsx +105 -0
  107. package/data/examples/minimal.tsx +78 -0
  108. package/data/examples/mui-theme.tsx +136 -0
  109. package/data/examples/multi-sorting.tsx +58 -0
  110. package/data/examples/persistent-state.tsx +184 -0
  111. package/data/examples/react-query.tsx +182 -0
  112. package/data/examples/remote.tsx +150 -0
  113. package/data/examples/row-actions-buttons.tsx +89 -0
  114. package/data/examples/row-actions-menu-items.tsx +64 -0
  115. package/data/examples/single-row-selection.tsx +98 -0
  116. package/data/examples/virtualized.tsx +138 -0
  117. package/data/guides/accessibility.md +119 -0
  118. package/data/guides/aggregation.md +210 -0
  119. package/data/guides/async-loading.md +132 -0
  120. package/data/guides/best-practices.md +363 -0
  121. package/data/guides/cell-actions.md +139 -0
  122. package/data/guides/click-to-copy.md +67 -0
  123. package/data/guides/column-actions.md +69 -0
  124. package/data/guides/column-filtering.md +366 -0
  125. package/data/guides/column-grouping.md +192 -0
  126. package/data/guides/column-hiding.md +133 -0
  127. package/data/guides/column-ordering-dnd.md +99 -0
  128. package/data/guides/column-pinning.md +72 -0
  129. package/data/guides/column-resizing.md +157 -0
  130. package/data/guides/column-size.md +162 -0
  131. package/data/guides/customize-components.md +395 -0
  132. package/data/guides/customize-icons.md +35 -0
  133. package/data/guides/data-columns.md +292 -0
  134. package/data/guides/density-toggle.md +46 -0
  135. package/data/guides/detail-panel.md +195 -0
  136. package/data/guides/display-columns.md +135 -0
  137. package/data/guides/editing.md +367 -0
  138. package/data/guides/expanding-sub-rows.md +194 -0
  139. package/data/guides/full-screen-toggle.md +63 -0
  140. package/data/guides/global-filtering.md +237 -0
  141. package/data/guides/localization.md +57 -0
  142. package/data/guides/memoization.md +157 -0
  143. package/data/guides/pagination.md +171 -0
  144. package/data/guides/row-actions.md +116 -0
  145. package/data/guides/row-numbers.md +24 -0
  146. package/data/guides/row-ordering-dnd.md +51 -0
  147. package/data/guides/row-pinning.md +96 -0
  148. package/data/guides/row-selection.md +237 -0
  149. package/data/guides/sorting.md +190 -0
  150. package/data/guides/state-management.md +165 -0
  151. package/data/guides/sticky-header.md +41 -0
  152. package/data/guides/table-event-listeners.md +103 -0
  153. package/data/guides/toolbar-customization.md +251 -0
  154. package/data/guides/virtualization.md +183 -0
  155. package/data/index.json +1930 -0
  156. package/data/reference/mrt-components.md +183 -0
  157. package/data/reference/mrt-hooks.md +125 -0
  158. package/data/skills/composable-components/SKILL.md +189 -0
  159. package/data/skills/customization/SKILL.md +190 -0
  160. package/data/skills/drag-and-drop-ordering/SKILL.md +227 -0
  161. package/data/skills/editing/SKILL.md +243 -0
  162. package/data/skills/filtering/SKILL.md +213 -0
  163. package/data/skills/getting-started/SKILL.md +213 -0
  164. package/data/skills/localization/SKILL.md +182 -0
  165. package/data/skills/migrate-v3-to-v4/SKILL.md +161 -0
  166. package/data/skills/state-and-server-data/SKILL.md +200 -0
  167. package/data/skills/virtualization/SKILL.md +203 -0
  168. package/dist/data.js +137 -0
  169. package/dist/index.js +232 -0
  170. package/package.json +50 -0
@@ -0,0 +1,237 @@
1
+ ## Global Filtering (Search) Feature Guide
2
+
3
+ Material React Table has a powerful built-in global filtering (search) feature that uses a fuzzy matching algorithm and ranks/sorts the results based on how closely rows match the search query. In this guide, we'll cover how to use, customize, or disable the global filter and search features to fit your needs.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enableFilterMatchHighlighting` - type `boolean` - default `true` - Enable or disable highlighting text that matches the filter in the table cells.
10
+ - `enableGlobalFilter` - type `boolean` - default `true`
11
+ - `enableGlobalFilterModes` - type `boolean` - default `true`
12
+ - `enableGlobalFilterRankedResults` - type `boolean` - default `true`
13
+ - `getColumnCanGlobalFilter` - type `(column: Column<TData, unknown>) => boolean`
14
+ - `globalFilterFn` - type `MRT_FilterOption` - The filter function to use for global filtering.
15
+ - `globalFilterModeOptions` - type `Array<MRT_FilterOption | string> | null`
16
+ - `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.
17
+ - `muiSearchTextFieldProps` - type `TextFieldProps | ({ table }) => TextFieldProps`
18
+ - `onGlobalFilterChange` - type `OnChangeFn<GlobalFilterState>` - If provided, this function will be called with an updaterFn when state.globalFilter 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.
19
+ - `onGlobalFilterFnChange` - type `OnChangeFn<GlobalFilterState>` - If provided, this function will be called with an updaterFn when state.globalFilter 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.
20
+ - `onShowGlobalFilterChange` - type `OnChangeFn<boolean>`
21
+ - `positionGlobalFilter` - type `'left' | 'right'` - default `'right'`
22
+ - `renderGlobalFilterModeMenuItems` - type `({ internalFilterOptions, onSelectFilterMode, table }) => ReactNode[]`
23
+
24
+ ### Relevant Column Options
25
+
26
+ Relevant column options (get_mrt_api has full details):
27
+
28
+ - `enableFilterMatchHighlighting` - type `boolean` - Enable or disable filter match highlighting for this column.
29
+ - `enableGlobalFilter` - type `boolean`
30
+
31
+ ### Relevant State Options
32
+
33
+ Relevant state options (get_mrt_api has full details):
34
+
35
+ - `globalFilter` - type `any`
36
+ - `globalFilterFn` - type `MRT_FilterFn`
37
+ - `showGlobalFilter` - type `boolean` - default `false`
38
+
39
+ ### Disable Global Filtering
40
+
41
+ You can either disable the global filter feature entirely or disable it for specific columns.
42
+
43
+ #### Disable Global Filtering per Column
44
+
45
+ If you simply want to not include a column as one of the columns that the global filter scans through during filtering, you can set the `enableGlobalFilter` option to `false` for that column.
46
+
47
+ ```tsx
48
+ const columns = [
49
+ {
50
+ accessorKey: 'id',
51
+ header: 'Id',
52
+ enableGlobalFilter: false, // do not scan this column during global filtering
53
+ },
54
+ {
55
+ accessorKey: 'name',
56
+ header: 'Name',
57
+ },
58
+ ];
59
+ ```
60
+
61
+ #### Disable Global Filter Feature
62
+
63
+ You can disable the global filtering feature and hide the search icon by setting the `enableGlobalFilter` table option to `false`.
64
+
65
+ ```tsx
66
+ const table = useMaterialReactTable({
67
+ columns,
68
+ data,
69
+ enableGlobalFilter: false, //disable search feature
70
+ });
71
+
72
+ return <MaterialReactTable table={table} />;
73
+ ```
74
+
75
+ ### Client-Side Global Filtering
76
+
77
+ Client-side filtering (and global filtering) is enabled by default. This means that the search box will scan through all columns and try to find matches for the search term.
78
+
79
+ #### Global Filter Function
80
+
81
+ You can use any of the built-in `filterFns` or any of the custom filter functions that you have defined in the `filterFns` prop, just like you would with the column filters.
82
+
83
+ ```jsx
84
+ const table = useMaterialReactTable({
85
+ columns,
86
+ data,
87
+ globalFilterFn: 'contains', //turn off fuzzy matching and use simple contains filter function
88
+ });
89
+ ```
90
+
91
+ Or a custom filter function:
92
+
93
+ ```jsx
94
+ const table = useMaterialReactTable({
95
+ columns,
96
+ data,
97
+ filterFns: {
98
+ myCustomFilterFn: (row, id, filterValue) =>
99
+ row.getValue(id).startsWith(filterValue),
100
+ },
101
+ globalFilterFn: 'myCustomFilterFn', //set the global filter function to myCustomFilterFn
102
+ });
103
+ ```
104
+
105
+ The default global filter function is set to `fuzzy`, which is a filtering algorithm based on the popular `match-sorter` [library from Kent C. Dodds](https://www.npmjs.com/package/match-sorter), though you can change the global filter function by setting the `globalFilterFn` table option.
106
+
107
+ #### Ranked Results
108
+
109
+ If you keep the default `fuzzy` filterFn option as the global filter function, you get an extra ranked results feature enabled by default. This means that when a user searches with the search box, the results will be sorted by the closest match first instead of the order the data was defined in.
110
+
111
+ The ranked results feature will disable itself automatically if a sort direction is applied to a column, if any sub-rows are expanded, or if any of the `manual` props are set to `true`.
112
+
113
+ If you do not want ranked results to be enabled at all, but you still want fuzzy matching, you can set the `enableGlobalFilterRankedResults` table option to `false`.
114
+
115
+ ```jsx
116
+ const table = useMaterialReactTable({
117
+ columns,
118
+ data,
119
+ enableGlobalFilterRankedResults: false, //preserve the order of the data when fuzzy match searching
120
+ });
121
+ ```
122
+
123
+ #### Global Filter Modes
124
+
125
+ Similar to the column filter modes, you can enable the user to be able to choose between multiple different filter modes for the global filter with the `enableGlobalFilterModes` table option. You can then customize which filter modes are available in the drop-down by setting the `globalFilterModeOptions` table option or by rendering your own custom menu items with the `renderGlobalFilterModeMenuItems` table option.
126
+
127
+ ```jsx
128
+ const table = useMaterialReactTable({
129
+ columns,
130
+ data,
131
+ enableGlobalFilterModes: true, //enable the user to choose between multiple search filter modes
132
+ globalFilterModeOptions: ['fuzzy', 'startsWith'], //only allow the user to choose between fuzzy and startsWith filter modes
133
+ });
134
+ ```
135
+
136
+ #### Show Search Field by Default
137
+
138
+ Additionally, if you want to show the search text box by default and not hide it behind the search icon, you can set the `showGlobalFilter` state to `true` in the `initialState`.
139
+
140
+ ### Manual Server-Side Global Filtering
141
+
142
+ 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 `globalFilter` state yourself like in the example below (can work in conjunction with [manual column filtering](/docs/guides/column-filtering#manual-server-side-column-filtering)).
143
+
144
+ ```tsx
145
+ // You can manage and have control over the columnFilters state yourself
146
+ const [globalFilter, setGlobalFilter] = useState('');
147
+ const [data, setData] = useState([]); //data will get updated after re-fetching
148
+
149
+ useEffect(() => {
150
+ const fetchData = async () => {
151
+ // send api requests when columnFilters state changes
152
+ const filteredData = await fetch();
153
+ setData([...filteredData]);
154
+ };
155
+ }, [globalFilter]);
156
+
157
+ const table = useMaterialReactTable({
158
+ columns,
159
+ data, // this will already be filtered on the server
160
+ manualFiltering: true, //turn off client-side filtering
161
+ onGlobalFilterChange: setGlobalFilter, //hoist internal global state to your state
162
+ state: { globalFilter }, //pass in your own managed globalFilter state
163
+ });
164
+
165
+ return <MaterialReactTable table={table} />;
166
+ ```
167
+
168
+ > Specifying `manualFiltering` turns off all client-side filtering and assumes that the `data` you pass to `<MaterialReactTable />` is already filtered.
169
+
170
+ Here is the full Remote Data example showing off server-side **filtering**, pagination, and sorting.
171
+
172
+ > Live example: `remote` (call get_mrt_example with that id).
173
+
174
+ ### Customize Global Filter Position
175
+
176
+ You can customize the position of the global filter (search box) in the top toolbar by setting the `positionGlobalFilter` table option to `left` or `right`. It is shown on the right by default.
177
+
178
+ ```jsx
179
+ const table = useMaterialReactTable({
180
+ columns,
181
+ data,
182
+ positionGlobalFilter: 'left', //show the global filter on the left side of the top toolbar
183
+ initialState: {
184
+ showGlobalFilter: true, //show the global filter by default
185
+ },
186
+ });
187
+ ```
188
+
189
+ ### Customize the Search Text Field
190
+
191
+ You can customize the search text field by passing in props to the `muiSearchTextFieldProps` table option. This is useful if you want to customize the placeholder text, add styles, or any other text field props.
192
+
193
+ ```jsx
194
+ const table = useMaterialReactTable({
195
+ columns,
196
+ data,
197
+ muiSearchTextFieldProps: {
198
+ placeholder: 'Search all users',
199
+ sx: { minWidth: '300px' },
200
+ variant: 'outlined',
201
+ },
202
+ });
203
+
204
+ return <MaterialReactTable table={table} />;
205
+ ```
206
+
207
+ > Live example: `customize-global-filter-component` (call get_mrt_example with that id).
208
+
209
+ ### Filter Match Highlighting
210
+
211
+ Filter match highlighting is a new featured enabled by default that will highlight text in the table body cells that matches the current search query with a shade of the `theme.palette.warning.main` color.
212
+
213
+ 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()` to preserve the filter match highlighting.
214
+
215
+ ```jsx
216
+ const columns = [
217
+ {
218
+ accessorKey: 'name',
219
+ header: 'Name',
220
+ Cell: ({ renderedCellValue }) => <span>{renderedCellValue}</span>, // use renderedCellValue instead of cell.getValue()
221
+ },
222
+ ];
223
+ ```
224
+
225
+ #### Disable Filter Match Highlighting
226
+
227
+ Filter match highlighting can be disabled by setting the `enableFilterMatchHighlighting` table option to `false`.
228
+
229
+ ```jsx
230
+ const table = useMaterialReactTable({
231
+ columns,
232
+ data,
233
+ enableFilterMatchHighlighting: false, //disable filter match highlighting
234
+ });
235
+ ```
236
+
237
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-search-examples)**
@@ -0,0 +1,57 @@
1
+ ## Localization (i18n) Guide
2
+
3
+ Material React Table has full support for localization (i18n). Some locales are included by default, but if your language is not yet supported, you can still easily add your own custom translations to the `localization` table option.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `localization` - type `MRT_Localization`
10
+
11
+ ### Built-in Locales
12
+
13
+ The following locales are included and can be imported from `'material-react-table/locales/'`:
14
+
15
+ `ar`, `az`, `bg`, `cs`, `da`, `de`, `el`, `en`, `es`, `et`, `fa`, `fi`, `fr`, `he`, `hr`, `hu`, `hy`, `id`, `it`, `ja`, `ko`, `nl`, `no`, `np`, `pl`, `pt`, `pt-BR`, `ro`, `ru`, `sk`, `sr-Cyrl-RS`, `sr-Latn-RS`, `sv`, `tr`, `uk`, `vi`, `zh-Hans`, `zh-Hant`
16
+
17
+ > If your language is not yet supported, please consider making a PR to add it to the library! See [here on GitHub](https://github.com/gyminii/material-react-table/tree/v4/packages/material-react-table/src/locales).
18
+
19
+ #### Built-in Locale Examples
20
+
21
+ Scroll and find your language below to see an example of how to use it.
22
+
23
+ > Live examples: `localization-i18n-ar`, `localization-i18n-az`, `localization-i18n-bg`, `localization-i18n-cs`, `localization-i18n-da`, `localization-i18n-de`, `localization-i18n-el`, `localization-i18n-en`, `localization-i18n-es`, `localization-i18n-et`, `localization-i18n-fa`, `localization-i18n-fi`, `localization-i18n-fr`, `localization-i18n-he`, `localization-i18n-hr`, `localization-i18n-hu`, `localization-i18n-hy`, `localization-i18n-id`, `localization-i18n-it`, `localization-i18n-ja`, `localization-i18n-ko`, `localization-i18n-nl`, `localization-i18n-no`, `localization-i18n-np`, `localization-i18n-pl`, `localization-i18n-pt`, `localization-i18n-ro`, `localization-i18n-ru`, `localization-i18n-sk`, `localization-i18n-sv`, `localization-i18n-tr`, `localization-i18n-uk`, `localization-i18n-vi`, `localization-i18n-zh-hans`, `localization-i18n-zh-hant` (call get_mrt_example with an id).
24
+
25
+ > Note: In some frameworks like Remix, you may need to use a full import path like <br /> `import { MRT_Localization_ES } from 'material-react-table/locales/es/index.js';` or <br /> `import { MRT_Localization_ES } from 'material-react-table/locales/es/index.esm.js';` <br />
26
+ > to properly import the locale.
27
+
28
+ ### Custom Non-Built-In Translations
29
+
30
+ If you want to use a language that is not included in the library, you can still easily add your own custom translations to the `localization` table option.
31
+
32
+ ```jsx
33
+ const table = useMaterialReactTable({
34
+ columns,
35
+ data,
36
+ localization: {
37
+ language: 'pt', // BCP 47 language tag for number formatting
38
+ actions: 'Ações',
39
+ and: 'e',
40
+ cancel: 'Cancelar',
41
+ changeFilterMode: 'Alterar o modo de filtro',
42
+ changeSearchMode: 'Alterar o modo de pesquisa',
43
+ clearFilter: 'Limpar filtros',
44
+ clearSearch: 'Limpar pesquisa',
45
+ clearSort: 'Limpar classificações',
46
+ clickToCopy: 'Clique para copiar',
47
+ // ... and many more - see link below for full list of translation keys
48
+ },
49
+ });
50
+
51
+ return <MaterialReactTable table={table} />;
52
+ ```
53
+
54
+ For a full list of all available translation keys, see [here](https://github.com/gyminii/material-react-table/blob/v4/packages/material-react-table/src/locales/en.ts).
55
+ Please note that each localization object should include a `language` property containing a valid BCP 47 language tag to ensure proper number formatting.
56
+
57
+ If you end up fully translating MRT into another language that is not yet supported, please consider making a PR to add it to the library so that everyone can use it!
@@ -0,0 +1,157 @@
1
+ ## Memoization (Performance) Guide
2
+
3
+ Material React Table already uses some memoization techniques to improve performance for you automatically under the hood to improve performance during some events like column resizing. In this guide, we'll go over the basics of what is recommended to be memoized, what you need to keep in mind for performance, and how to tweak advanced memoization settings for your specific use case.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `columns` - type `Array<MRT_ColumnDef<TData>>` - The array of column defs to use for the table.
10
+ - `data` - type `Array<TData>` - The data for the table to display. This can be an array of anything, but you will need to set up your column definitions to "access" the data. When the data option changes reference (compared via Object.is), the table will reprocess the data. Any other data processing that relies on the core data model (such as grouping, sorting, filtering, etc) will also be reprocessed.
11
+ - `memoMode` - type `'cells' | 'rows' | 'table-body'`
12
+
13
+ ### What to Memoize
14
+
15
+ First of all, when these docs refer to memoization, we are not necessarily talking just about the React `useMemo` hook. Using the `useMemo` hook is just one way to give an variable a stable reference in React. `useMemo`, `useState`, `useReducer`, `useQuery` (React Query), storing state in a state management library like Zustand or Redux, or even just defining a variable outside of a component are all ways to give a variable a stable reference.
16
+
17
+ #### Give Data a Stable Reference
18
+
19
+ The only truly required thing that must have a stable reference for both Material React Table and TanStack Table is the `data` table option. If your `data` does not have a stable reference, the table will enter an infinite loop of re-rendering upon any state change.
20
+
21
+ > Failing to give `data` a stable reference can cause an infinite loop of re-renders.
22
+
23
+ ##### _Why does this happen? Is this a bug in MRT or TanStack Table?_
24
+
25
+ No, this is not a bug in either MRT or TanStack Table. This is just fundamentally how React works. TanStack Table is designed to re-render whenever the `data` changes. You would probably be equally surprised and upset if MRT only accepted what you passed in as `data` on the first render and never updated after a refetch or state change.
26
+
27
+ ```jsx
28
+ export default function MyComponent() {
29
+ const columns = [
30
+ // ...
31
+ ];
32
+
33
+ //😵 BAD: This will cause an infinite loop of re-renders because `data` is redefined as a new array on every render
34
+ const data = [
35
+ // ...
36
+ ];
37
+
38
+ const table = useMaterialReactTable({
39
+ columns,
40
+ data, //data is defined as a const in the same scope as `useMaterialReactTable`, will cause infinite loop
41
+ });
42
+
43
+ return <MaterialReactTable table={table} />;
44
+ }
45
+ ```
46
+
47
+ ##### I'm still getting an infinite loop of re-renders, but I'm using useMemo!
48
+
49
+ Sometimes developers will properly memoize their `data`, but don't end up passing that memoized `data` to the table, and apply some extra transformation or filtering to the `data` before passing it to the table. This common mistake will still cause an infinite loop of re-renders.
50
+
51
+ ```jsx
52
+ export default function MyComponent() {
53
+ const columns = [
54
+ // ...
55
+ ];
56
+
57
+ //GOOD: Storing `data` in state gives it a stable reference
58
+ const [data, setData] = useState([
59
+ // ...
60
+ ]);
61
+
62
+ //GOOD: This still preserves the stable reference of `data` and will not cause an infinite loop of re-renders
63
+ const filteredData = useMemo(
64
+ () => data.filter((row) => row.isActive),
65
+ [data],
66
+ );
67
+
68
+ const table = useMaterialReactTable({
69
+ columns,
70
+ //GOOD: Reading from the `data` state is stable
71
+ data,
72
+
73
+ //😵 BAD: This is ignoring the stable reference of `data` and re-creating a new array on every render
74
+ data: data.filter((row) => row.isActive),
75
+
76
+ //GOOD: This is still reading from the stable reference from a `useMemo` hook
77
+ data: filteredData,
78
+ });
79
+
80
+ return <MaterialReactTable table={table} />;
81
+ }
82
+ ```
83
+
84
+ #### Memoize Columns
85
+
86
+ You will generally have better performance if you properly memoize your `columns` array, or give it a stable reference like you would with `data`. Not giving `columns` a stable reference will not cause an infinite loop of re-renders like `data`, but it will still cause the table to re-render more than necessary. The columns `useMemo` dependency array does not need to be an empty array. If your column definitions are derived from other state, you should include that state in the dependency array.
87
+
88
+ ```jsx
89
+ const columns = useMemo(
90
+ () => [
91
+ // ...
92
+ ],
93
+ [],
94
+ );
95
+
96
+ //OR
97
+
98
+ const columns = useMemo(
99
+ () => [
100
+ // ...
101
+ ],
102
+ [dependency1, dependency2], //if column defs are derived from other state, don't forget to include that state in the dependency array
103
+ );
104
+
105
+ //OR
106
+
107
+ const [columns, setColumns] = useState(() => [
108
+ // ...
109
+ ]);
110
+ ```
111
+
112
+ #### Other Options to Memoize
113
+
114
+ Usually you will not need to memoize any other options besides `columns` and `data`. However, if you have any expensive logic in any of the `render*` options, you may benefit from wrapping that logic in a React `useCallback` hook. It is not recommended to start off by wrapping all of your `render*` options in `useCallback` hooks, as this usually does not even provide a noticeable performance improvement. This usually takes some experimentation.
115
+
116
+ Here's an example for how to render detail panels with a `useCallback` optimization. Getting the TypeScript types correct in the `useCallback` can be tricky, but here's how you can do it:
117
+
118
+ ```tsx
119
+ const table = useMaterialReactTable({
120
+ columns,
121
+ data,
122
+ renderDetailPanel: useCallback<
123
+ Required<MRT_TableOptions<Person>>['renderDetailPanel'] //TS needed to get the correct type of the inner arrow function below
124
+ >(
125
+ ({ row, table }) =>
126
+ <DetailPanelComponent row={row} />
127
+ [], //add proper dependencies here if needed
128
+ ),
129
+ });
130
+ ```
131
+
132
+ All of the other `mui*Props` components could also be memoized with either `useMemo` or `useCallback` if you have complicated expensive logic in them for some reason in the same way as above.
133
+
134
+ ### Memo Mode
135
+
136
+ Material React Table already memoizes columns and the entire `<tbody>` component during column resizing, and column/row drag and drop events. This actually does make a significant performance improvement, and is why it is possible to have the performance that it does during these events.
137
+
138
+ If you need to reach into the internals and apply some custom memoization, MRT exposes a limited way to do this. The Table Body, Table Rows, or all Table Cells can be memoized with the `memoMode` table option.
139
+
140
+ ```jsx
141
+ const table = useMaterialReactTable({
142
+ columns,
143
+ data,
144
+ //memoize all cells. This value can be applied dynamically based on a certain scenario/condition if needed
145
+ memoMode: 'cells', // 'cells' | 'rows' | 'table-body'
146
+ });
147
+ ```
148
+
149
+ Usually you should not ever need to do this, and be aware that this will stop certain features from functioning correctly. For example, if you memoize all table cells, the density toggle feature will not work anymore. If you memoize the entire table body, most features including virtualization will not work anymore. You'll be left with a table that is mostly frozen after first render, but it could improve the overall performance of your web page if you don't need any of these interactive features.
150
+
151
+ > Don't use `memoMode` unless you know what you're doing and have a specific use case for it.
152
+
153
+ ### React Forget
154
+
155
+ In the future, React may finally release their magical "React Forget" compiler that will make all memoization problems in React disappear, and you won't have to worry about any of this. But until then, the above solutions are the best we have.
156
+
157
+ View Extra Storybook [Examples](https://www.material-react-table.dev/?path=/story/features-memo-mode-examples)
@@ -0,0 +1,171 @@
1
+ ## Pagination Feature Guide
2
+
3
+ Client-side pagination is enabled by default in Material React Table. There are a number of ways to customize pagination, turn off pagination, or completely replace the built-in pagination with your own manual or server-side pagination logic.
4
+
5
+ ### Relevant Table Options
6
+
7
+ Relevant table options (get_mrt_api has full details):
8
+
9
+ - `enablePagination` - type `boolean` - default `true`
10
+ - `manualPagination` - type `boolean` - Enables manual pagination. If this option is set to true, the table will not automatically paginate rows and instead will expect you to manually paginate the rows before passing them to the table. This is useful if you are doing server-side pagination and aggregation.
11
+ - `muiPaginationProps` - type `Partial<PaginationProps> | ({ table }) => Partial<PaginationProps>`
12
+ - `onPaginationChange` - type `OnChangeFn<PaginationState>` - If this function is provided, it will be called when the pagination 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.pagination option.
13
+ - `pageCount` - type `number` - When manually controlling pagination, you should supply a total pageCount value to the table if you know it. If you do not know how many pages there are, you can set this to -1.
14
+ - `paginateExpandedRows` - type `boolean` - If true expanded rows will be paginated along with the rest of the table (which means expanded rows may span multiple pages). If false expanded rows will not be considered for pagination (which means expanded rows will always render on their parents page. This also means more rows will be rendered than the set page size)
15
+ - `positionPagination` - type `'bottom' | 'top' | 'both'` - default `'bottom'`
16
+ - `rowCount` - type `number`
17
+
18
+ ### Relevant State Options
19
+
20
+ Relevant state options (get_mrt_api has full details):
21
+
22
+ - `pagination` - type `{ pageIndex: number, pageSize: number } ` - default `{ pageIndex: 0, pageSize: 10 }`
23
+
24
+ ### Disable Pagination
25
+
26
+ If you simply want to disable pagination, you can set the `enablePagination` table option to `false`. This will both hide the pagination controls and disable the pagination functionality.
27
+
28
+ If you only want to disable the pagination logic, but still want to show and use the pagination controls, take a look down below at the [Manual Pagination](#manual-or-server-side-pagination) docs.
29
+
30
+ ```jsx
31
+ const table = useMaterialReactTable({
32
+ columns,
33
+ data,
34
+ enablePagination: false,
35
+ enableBottomToolbar: false, //hide the bottom toolbar as well if you want
36
+ });
37
+ ```
38
+
39
+ ### Customize Pagination
40
+
41
+ #### Pagination State
42
+
43
+ If you want to change the rows per page value or the initial page index, you can do that through either the `initialState` or `state` table option.
44
+
45
+ ```jsx
46
+ //using initialState if you do not need to manage the pagination state yourself
47
+ const table = useMaterialReactTable({
48
+ columns,
49
+ data,
50
+ initialState: { pagination: { pageSize: 25, pageIndex: 2 } }, //customize the default page size and page index
51
+ });
52
+ ```
53
+
54
+ ```jsx
55
+ //using state if you want to manage the pagination state yourself
56
+ const [pagination, setPagination] = useState({
57
+ pageIndex: 0,
58
+ pageSize: 5, //customize the default page size
59
+ });
60
+
61
+ const table = useMaterialReactTable({
62
+ columns,
63
+ data,
64
+ onPaginationChange: setPagination, //hoist pagination state to your state when it changes internally
65
+ state: { pagination }, //pass the pagination state to the table
66
+ });
67
+ ```
68
+
69
+ > Note: Do not pass pagination state to both `initialState` and `state` at the same time. The `state` will overwrite the `initialState` values.
70
+
71
+ #### Customize Pagination Behavior
72
+
73
+ There are a few table options that you can use to customize the pagination behavior. The first one is `autoResetPageIndex`. This table option is `true` by default, and causes a table to automatically reset the table back to the first page whenever sorting, filtering, or grouping occurs. This makes sense for most use cases, but if you want to disable this behavior, you can set this table option to `false`.
74
+
75
+ Next there is `paginateExpandedRows`, which works in conjunction expanding features. This table option is `true` by default, and forces the table to still only render the same number of rows per page that is set as the page size, even as sub-rows become expanded. However, this does cause expanded rows to sometimes not be on the same page as their parent row, so you can turn this off to keep sub rows with their parent row on the same page.
76
+
77
+ #### Customize Pagination Components
78
+
79
+ > Note: In v2, muiPaginationProps is now based on mui's `PaginationProps` instead of `TablePaginationProps`.
80
+
81
+ You can customize the pagination component with the `muiPaginationProps` table option to change things like the `rowsPerPageOptions` or whether or not to show the first and last page buttons, and more.
82
+
83
+ ```jsx
84
+ const table = useMaterialReactTable({
85
+ columns,
86
+ data,
87
+ muiPaginationProps: {
88
+ rowsPerPageOptions: [5, 10, 20],
89
+ showFirstButton: false,
90
+ showLastButton: false,
91
+ },
92
+ });
93
+ ```
94
+
95
+ #### Alternate Pagination UI
96
+
97
+ > New in v2
98
+
99
+ By default, Material React Table provides its own Table Pagination UI that is more compact and traditional for data tables. However, if you want to use the Material Pagination component instead, it is as easy as setting the `paginationDisplayMode` table option to `pages`.
100
+
101
+ ```jsx
102
+ const table = useMaterialReactTable({
103
+ columns,
104
+ data,
105
+ paginationDisplayMode: 'pages',
106
+ });
107
+ ```
108
+
109
+ > Live example: `alternate-pagination` (call get_mrt_example with that id).
110
+
111
+ ### Manual or Server-Side Pagination
112
+
113
+ #### Manual Pagination
114
+
115
+ The default pagination features are client-side. This means you have to have all of your data fetched and stored in the table all at once. This may not be ideal for large datasets, but do not worry, Material React Table supports server-side pagination.
116
+
117
+ When the `manualPagination` table option is set to `true`, Material React Table will assume that the `data` that is passed to the table already has had the pagination logic applied. Usually you would do this in your back-end logic.
118
+
119
+ #### Override Page Count and Row Count
120
+
121
+ If you are using manual pagination, the default page count and row count in the MRT Pagination component will be incorrect, as it is only derived from the number of rows provided in the client-side `data` table option. Luckily, you can override these values and set your own page count or row count in the `pageCount` and `rowCount` table options.
122
+
123
+ ```jsx
124
+ const table = useMaterialReactTable({
125
+ columns,
126
+ data,
127
+ manualPagination: true,
128
+ rowCount: data.meta.totalDBRowCount, //you can tell the pagination how many rows there are in your back-end data
129
+ });
130
+ ```
131
+
132
+ ### Manage Pagination State
133
+
134
+ For either client-side or server-side pagination, you may want to have access to the pagination state yourself. You can do this like so with `state`:
135
+
136
+ ```jsx
137
+ //store pagination state in your own state
138
+ const [pagination, setPagination] = useState({
139
+ pageIndex: 0,
140
+ pageSize: 5, //customize the default page size
141
+ });
142
+
143
+ useEffect(() => {
144
+ //do something when the pagination state changes
145
+ }, [pagination.pageIndex, pagination.pageSize]);
146
+
147
+ const table = useMaterialReactTable({
148
+ columns,
149
+ data,
150
+ onPaginationChange: setPagination, //hoist pagination state to your state when it changes internally
151
+ state: { pagination }, //pass the pagination state to the table
152
+ });
153
+
154
+ return <MaterialReactTable table={table} />;
155
+ ```
156
+
157
+ Alternatively, if all you care about is customizing the initial pagination state and do not need to react to its changes, like customizing the default page size or the page index, you can do that like so with `initialState`:
158
+
159
+ ```jsx
160
+ const table = useMaterialReactTable({
161
+ columns,
162
+ data,
163
+ initialState: { pagination: { pageSize: 25, pageIndex: 2 } },
164
+ });
165
+ ```
166
+
167
+ Here is the full Remote Data example showing off server-side filtering, **pagination**, and sorting.
168
+
169
+ > Live example: `remote` (call get_mrt_example with that id).
170
+
171
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-pagination-examples)**