@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,251 @@
1
+ ## Toolbar Customization Guide
2
+
3
+ This guide shows you how to [hide](#hide-or-disable-toolbars), [customize](#customize-toolbar-buttons), or [override](#override-with-custom-toolbar-components) the top and bottom toolbars in Material React Table.
4
+
5
+ > Note: This guide has become much more simple since the introduction of the `useMaterialReactTable` hook in v2. <br />
6
+ > No more `tableInstanceRef` or `useReducer` rerender hacks required!
7
+
8
+ ### Relevant Table Options
9
+
10
+ Relevant table options (get_mrt_api has full details):
11
+
12
+ - `enableBottomToolbar` - type `boolean` - default `true`
13
+ - `enableToolbarInternalActions` - type `boolean` - default `true`
14
+ - `enableTopToolbar` - type `boolean` - default `true`
15
+ - `muiBottomToolbarProps` - type `BoxProps | ({ table }) => BoxProps`
16
+ - `muiLinearProgressProps` - type `LinearProgressProps | ({ isTopToolbar, table }) => LinearProgressProps`
17
+ - `muiToolbarAlertBannerChipProps` - type `ChipProps| ({ table }} => ChipProps`
18
+ - `muiToolbarAlertBannerProps` - type `AlertProps | ({ table }) => AlertProps`
19
+ - `muiTopToolbarProps` - type `BoxProps | ({ table }) => BoxProps`
20
+ - `positionGlobalFilter` - type `'left' | 'right'` - default `'right'`
21
+ - `positionPagination` - type `'bottom' | 'top' | 'both'` - default `'bottom'`
22
+ - `positionToolbarAlertBanner` - type `'bottom' | 'top' | 'none'` - default `'top'`
23
+ - `positionToolbarDropZone` - type `'bottom' | 'top' | 'both' | 'none'` - default `'top'`
24
+ - `renderBottomToolbar` - type `ReactNode | ({ table }) => ReactNode`
25
+ - `renderBottomToolbarCustomActions` - type `({ table }) => ReactNode`
26
+ - `renderToolbarAlertBannerContent` - type `({ table, groupedAlert, selectedAlert }) => ReactNode`
27
+ - `renderToolbarInternalActions` - type `({ table}) => ReactNode`
28
+ - `renderTopToolbar` - type `ReactNode | ({ table }) => ReactNode`
29
+ - `renderTopToolbarCustomActions` - type `({ table }) => ReactNode`
30
+
31
+ ### Relevant State
32
+
33
+ Relevant state options (get_mrt_api has full details):
34
+
35
+ - `showAlertBanner` - type `boolean` - default `false`
36
+ - `showProgressBars` - type `boolean` - default `false`
37
+
38
+ ### Hide or Disable Toolbars
39
+
40
+ There are `enableTopToolbar` and `enableBottomToolbar` table options that you can use to show or hide the toolbars.
41
+
42
+ ```jsx
43
+ const table = useMaterialReactTable({
44
+ data,
45
+ columns,
46
+ enableTopToolbar: false,
47
+ enableBottomToolbar: false,
48
+ });
49
+
50
+ return <MaterialReactTable table={table} />;
51
+ ```
52
+
53
+ Alternatively, you could just use a different MRT component that does not have the toolbars built-in. For example, use the `<MRT_TableContainer />` or `<MRT_Table />` components instead of the `<MaterialReactTable />` component.
54
+
55
+ ```jsx
56
+ const table = useMaterialReactTable({
57
+ data,
58
+ columns,
59
+ });
60
+
61
+ //This MRT sub-component does not contain the code for the toolbars. MRT_TablePaper and MaterialReactTable do.
62
+ return <MRT_TableContainer table={table} />;
63
+ ```
64
+
65
+ #### No Toolbars Example
66
+
67
+ > Live example: `minimal` (call get_mrt_example with that id).
68
+
69
+ ### Customize Toolbar buttons
70
+
71
+ Everything in the toolbars are customizable. You can add your own buttons or change the order of the built-in buttons.
72
+
73
+ #### Customize Built-In Internal Toolbar Button Area
74
+
75
+ The `renderToolbarInternalActions` table option allows you to redefine the built-in buttons that usually reside in the top right of the top toolbar. You can reorder the icon buttons or even insert your own custom buttons. All of the built-in buttons are available to be imported from 'material-react-table'.
76
+
77
+ ```jsx
78
+ import {
79
+ MaterialReactTable,
80
+ MRT_ShowHideColumnsButton,
81
+ MRT_ToggleFullScreenButton,
82
+ } from 'material-react-table';
83
+
84
+ const table = useMaterialReactTable({
85
+ data,
86
+ columns,
87
+ renderToolbarInternalActions: ({ table }) => (
88
+ <>
89
+ {/* add your own custom print button or something */}
90
+ <IconButton onClick={() => showPrintPreview(true)}>
91
+ <PrintIcon />
92
+ </IconButton>
93
+ {/* built-in buttons (must pass in table prop for them to work!) */}
94
+ <MRT_ShowHideColumnsButton table={table} />
95
+ <MRT_ToggleFullScreenButton table={table} />
96
+ </>
97
+ ),
98
+ });
99
+
100
+ return <MaterialReactTable table={table} />;
101
+ ```
102
+
103
+ #### Add Custom Toolbar Buttons/Components
104
+
105
+ The `renderTopToolbarCustomActions` and `renderBottomToolbarCustomActions` table options allow you to add your own custom buttons or components to the top and bottom toolbar areas. These props are functions that return a ReactNode. You can add your own buttons or whatever components you want.
106
+
107
+ In all of these `render...` table options, you get access to the `table` instance that you can use to perform actions or extract data from the table.
108
+
109
+ ```jsx
110
+ const table = useMaterialReactTable({
111
+ data,
112
+ columns,
113
+ enableRowSelection: true,
114
+ //Simply adding a table title to the top-left of the top toolbar
115
+ renderTopToolbarCustomActions: () => (
116
+ <Typography variant="h3">Customer's Table</Typography>
117
+ ),
118
+ //Adding a custom button to the bottom toolbar
119
+ renderBottomToolbarCustomActions: ({ table }) => (
120
+ <Button
121
+ variant="contained"
122
+ color="lightblue"
123
+ //extract all selected rows from the table instance and do something with them
124
+ onClick={() => handleDownloadRows(table.getSelectedRowModel().rows)}
125
+ >
126
+ Download Selected Rows
127
+ </Button>
128
+ ),
129
+ });
130
+
131
+ return <MaterialReactTable table={table} />;
132
+ ```
133
+
134
+ #### Custom Toolbar Actions Example
135
+
136
+ > Live example: `custom-top-toolbar` (call get_mrt_example with that id).
137
+
138
+ ### Position Toolbar Areas
139
+
140
+ The `positionToolbarAlertBanner`, `positionGlobalFilter`, `positionPagination`, and `positionToolbarDropZone` table options allow you to swap the default position of certain areas of the toolbars. Experiment moving them around until you find a layout that works for you.
141
+
142
+ ```jsx
143
+ const table = useMaterialReactTable({
144
+ data,
145
+ columns
146
+ //if rendering top toolbar buttons, sometimes you want alerts to be at the bottom
147
+ positionToolbarAlertBanner: 'bottom',
148
+ positionGlobalFilter: 'left', //move the search box to the left of the top toolbar
149
+ positionPagination: 'top',
150
+ renderTopToolbarCustomActions: () => <Box>...</Box>,
151
+ });
152
+
153
+ return <MaterialReactTable table={table} />;
154
+ ```
155
+
156
+ ### Customize Toolbar Props and Styles
157
+
158
+ The `muiTopToolbarProps`, `muiBottomToolbarProps`, `muiToolbarAlertBannerProps`, and `muiToolbarAlertBannerChipProps` table options allow you to customize the props and styles of the underlying Material components that make up the toolbar components. Remember that you can pass CSS overrides to their `sx` or `style` props. Some have found this useful for forcing `position: absolute` on alerts, etc.
159
+
160
+ ### Customize Linear Progress Bars
161
+
162
+ The progress bars that display in both the top and bottom toolbars become visible when either the `isLoading` or `showProgressBars` state options are set to `true`. You can customize the progress bars by passing in props to the `muiLinearProgressProps` table option. By default, the progress bars have a full animated progress bar, but you can set the `value` table option to a number between 0 and 100 to show real progress values if your table is doing some complicated long running tasks that you want to show progress for. Visit the [Material UI Progress docs](https://mui.com/material-ui/react-progress/) to learn more.
163
+
164
+ ```jsx
165
+ const table = useMaterialReactTable({
166
+ data,
167
+ columns,
168
+ muiLinearProgressProps: ({ isTopToolbar }) => ({
169
+ color: 'warning',
170
+ sx: { display: isTopToolbar ? 'block' : 'none' }, //only show top toolbar progress bar
171
+ value: fetchProgress, //show precise real progress value if you so desire
172
+ }),
173
+ state: {
174
+ isLoading,
175
+ showProgressBars,
176
+ },
177
+ });
178
+
179
+ return <MaterialReactTable table={table} />;
180
+ ```
181
+
182
+ ### Customize Toolbar Alert Banner
183
+
184
+ The toolbar alert banner is an internal component used to display alerts to the user. By default, it will automatically show messages around the number of selected rows or grouping state.
185
+
186
+ However, you can repurpose this alert banner to show your own custom messages too. You can force the alert banner to show by setting the `showAlertBanner` state option to `true`. You can then customize the messages and other stylings using the `muiToolbarAlertBannerProps` to create your custom message. You probably saw this in the [Remote Data](/docs/examples/remote) or [React Query](/docs/examples/react-query) examples.
187
+
188
+ ```jsx
189
+ const table = useMaterialReactTable({
190
+ data,
191
+ columns,
192
+ //show a custom error message if there was an error fetching data in the top toolbar
193
+ muiToolbarAlertBannerProps: isError
194
+ ? {
195
+ color: 'error',
196
+ children: 'Network Error. Could not fetch data.',
197
+ }
198
+ : undefined,
199
+ state: {
200
+ showAlertBanner: isError,
201
+ showProgressBars: isFetching,
202
+ },
203
+ });
204
+
205
+ return <MaterialReactTable table={table} />;
206
+ ```
207
+
208
+ ### Override with Custom Toolbar Components
209
+
210
+ If you want to completely override the default toolbar components, you can do so by passing in your own custom components to the `renderTopToolbar` and `renderBottomToolbar` props.
211
+
212
+ The drawback to this approach is that you will not get all the automatic features of the default toolbar components, such as the automatic alert banner, progress bars, etc. You will have to implement all of that yourself if you still want those features. Though you can also just import those MRT components and use them in your custom toolbar.
213
+
214
+ ```jsx
215
+ import {
216
+ MRT_GlobalFilterTextInput, //import MRT sub components!
217
+ MRT_TablePagination,
218
+ MaterialReactTable,
219
+ useMaterialReactTable,
220
+ } from 'material-react-table';
221
+
222
+ const table = useMaterialReactTable({
223
+ data,
224
+ columns,
225
+ renderTopToolbar: ({ table }) => (
226
+ <Box
227
+ sx={{
228
+ display: 'flex',
229
+ justifyContent: 'space-between',
230
+ alignItems: 'center',
231
+ }}
232
+ >
233
+ <MRT_GlobalFilterTextInput table={table} />
234
+ <MRT_TablePagination table={table} />
235
+ </Box>
236
+ ),
237
+ renderBottomToolbar: ({ table }) => (
238
+ <Box>
239
+ <Button>Download</Button>
240
+ </Box>
241
+ ),
242
+ });
243
+
244
+ return <MaterialReactTable table={table} />;
245
+ ```
246
+
247
+ ### Build Your Own Toolbar
248
+
249
+ Instead of overriding the toolbar components up above, you may want 100% control over the layout and styling of your table controls and where they are on the page. You can do this by just using a MRT sub component such as `<MRT_TableContainer />` for the table component, which does not have the internal toolbar components built-in. Optionally, build your own custom toolbar components using the other MRT sub components.
250
+
251
+ > Live example: `external-toolbar` (call get_mrt_example with that id).
@@ -0,0 +1,183 @@
1
+ ## Virtualization Feature Guide
2
+
3
+ > MRT v1.4 and v1.5 have major virtualization upgrades after switching to `@tanstack/react-virtual` v3.0!
4
+
5
+ Virtualization is useful when you have a lot of data you want to display client-side all at once without having to use pagination. Material React Table makes this as simple as possible, thanks to [`@tanstack/react-virtual`](https://tanstack.com/virtual/v3) with both [row virtualization](#enable-row-virtualization) and [column virtualization](#enable-column-virtualization) support.
6
+
7
+ > NOTE: You should only enable row virtualization if you have a large number of rows. Depending on the size of the table, if you are rendering less than a couple dozen rows at a time, you will actually just be adding extra overhead to the table renders. Virtualization only becomes necessary when you have more than 50 rows or so at the same time with no pagination.
8
+
9
+ ### Relevant Table Options
10
+
11
+ Relevant table options (get_mrt_api has full details):
12
+
13
+ - `columnVirtualizerInstanceRef` - type `MutableRefObject<Virtualizer | null>`
14
+ - `columnVirtualizerOptions` - type `Partial<VirtualizerOptions<HTMLDivElement, HTMLTableCellElement>>`
15
+ - `enableColumnVirtualization` - type `boolean` - Enables column virtualization and creates an MRT_ColumnVirtualizer instance internally. This option CANNOT be enabled conditionally. Other side effects include layoutMode will be set either to "grid" or "grid-no-grow"
16
+ - `enableRowVirtualization` - type `boolean` - Enables row virtualization and creates an MRT_RowVirtualizer instance internally. This option CANNOT be enabled conditionally. Other side effects include layoutMode will be set either to "grid" or "grid-no-grow"
17
+ - `rowVirtualizerInstanceRef` - type `MutableRefObject<Virtualizer | null>`
18
+ - `rowVirtualizerOptions` - type `Partial<VirtualizerOptions<HTMLDivElement, HTMLTableRowElement>>`
19
+
20
+ ### What is Virtualization?
21
+
22
+ Virtualization, or virtual scrolling, works by only rendering the rows or columns that are visible on the screen. This is useful for performance and user experience, as we can make it appear that there are hundreds, thousands, or even tens of thousands of rows in the table all at once, but in reality, the table will only render the couple dozen rows that are visible on the screen, or the handful of columns that are visible on the screen.
23
+
24
+ For more reading on the concept of virtualization, we recommend this [blog post](https://blog.logrocket.com/virtual-scrolling-core-principles-and-basic-implementation-in-react/) by LogRocket.
25
+
26
+ ### Does Your Table Even Need Virtualization?
27
+
28
+ If your table is paginated or you are not going to render more than 50 rows at once, you probably do not need row virtualization.
29
+
30
+ If your table does not have more than 12 columns, you probably do not need column virtualization.
31
+
32
+ There is a slight amount of extra overhead that gets added to your table's rendering when virtualization is enabled, so do not just enable it for every table. That being said, if your table does have well more than 100 rows that it is trying to render all at once without pagination, performance should improve significantly once it has been enabled.
33
+
34
+ ### Enable Row Virtualization
35
+
36
+ Enabling row virtualization is as simple as setting the `enableRowVirtualization` table option to `true`. However, you will probably also want to turn off pagination, which you can do by setting `enablePagination` to `false`.
37
+
38
+ ```tsx
39
+ <MaterialReactTable
40
+ columns={columns}
41
+ data={data}
42
+ enablePagination={false}
43
+ enableRowVirtualization
44
+ />
45
+ ```
46
+
47
+ Take a look at the example below with 10,000 rows!
48
+
49
+ > Live example: `enable-row-virtualization` (call get_mrt_example with that id).
50
+
51
+ ### Enable Column Virtualization
52
+
53
+ Enabling column virtualization is also as simple as setting the `enableColumnVirtualization` table option to `true`.
54
+
55
+ ```tsx
56
+ <MaterialReactTable columns={columns} data={data} enableColumnVirtualization />
57
+ ```
58
+
59
+ Take a look at the example below with 500 columns!
60
+
61
+ > Live example: `enable-column-virtualization` (call get_mrt_example with that id).
62
+
63
+ > WARNING: Do not enable row or column virtualization conditionally. This could break React's Rule of Hooks and/or cause other UI jumpiness.
64
+
65
+ ### Virtualization Side Effects
66
+
67
+ When either row or column virtualization is enabled, a few other props automatically get set internally.
68
+
69
+ #### `layoutMode` Prop
70
+
71
+ In MRT Versions 1.3 and earlier, a CSS `table-layout: fixed` style was automatically added to the `<table>` element to prevent columns from wiggling back and forth during scrolling due to body cells having varying widths.
72
+
73
+ But now in MRT Versions 1.4 and later, the `layoutMode` table option is automatically set to the `'grid'` value when either row or column virtualization is enabled, which means that all of the table markup will use CSS Grid and Flexbox instead of the traditional semantic styles that usually come with table tags. This is necessary to make the virtualization work properly with decent performance.
74
+
75
+ #### `enableStickyHeader` Prop
76
+
77
+ The `enableStickyHeader` table option is automatically set to `true` when row virtualization is enabled. This keeps the table header sticky and visible while scrolling and adds a default max-height of 100vh to the table container.
78
+
79
+ ### Customize Virtualizer Props
80
+
81
+ You can adjust some of the virtualizer props that are used internally with the `rowVirtualizerOptions` and `columnVirtualizerOptions` props. The most useful virtualizer props are the `overscan` and `estimateSize` options. You may want to adjust these values if you have unusual row heights or column widths that are causing the default scrolling to behave strangely.
82
+
83
+ ```jsx
84
+ <MaterialReactTable
85
+ columns={columns}
86
+ data={data}
87
+ enableColumnVirtualization
88
+ enablePagination={false}
89
+ enableRowVirtualization
90
+ columnVirtualizerOptions={{
91
+ overscan: 5, //adjust the number of columns that are rendered to the left and right of the visible area of the table
92
+ estimateSize: () => 400, //if your columns are wider or , try tweaking this value to make scrollbar size more accurate
93
+ }}
94
+ rowVirtualizerOptions={{
95
+ overscan: 10, //adjust the number or rows that are rendered above and below the visible area of the table
96
+ estimateSize: () => 100, //if your rows are taller than normal, try tweaking this value to make scrollbar size more accurate
97
+ }}
98
+ />
99
+ ```
100
+
101
+ See the official TanStack [Virtualizer Options API Docs](https://tanstack.com/virtual/v3/docs/api/virtualizer#optional-options) for more information.
102
+
103
+ > MRT v1.4 upgraded from `react-virtual` v2 to `@tanstack/react-virtual` v3.0, which has some breaking changes and virtualizer option name changes. TypeScript hints should help you with any prop name changes, but you can also view the official [TanStack Virtual Docs](https://tanstack.com/virtual/v3/docs/api/virtualizer#optional-options) for guidance.
104
+
105
+ ### Access Underlying Virtualizer Instances
106
+
107
+ In a similar way that you can [access the underlying table instance](/docs/guides/table-state-management#access-the-underlying-table-instance-reference), you can also access the underlying virtualizer instances. This can be useful for accessing methods like the `scrollToIndex` method, which can be used to programmatically scroll to a specific row or column.
108
+
109
+ ```tsx
110
+ const columnVirtualizerInstanceRef = useRef<MRT_ColumnVirtualizer>(null);
111
+ const rowVirtualizerInstanceRef = useRef<MRT_RowVirtualizer>(null);
112
+
113
+ useEffect(() => {
114
+ if (rowVirtualizerInstanceRef.current) {
115
+ //scroll to the top of the table when sorting changes
116
+ rowVirtualizerInstanceRef.current.scrollToIndex(0);
117
+ }
118
+ }, [sorting]);
119
+
120
+ return (
121
+ <MaterialReactTable
122
+ columns={columns}
123
+ data={data}
124
+ enableColumnVirtualization
125
+ enableRowVirtualization
126
+ rowVirtualizerInstanceRef={rowVirtualizerInstanceRef}
127
+ columnVirtualizerInstanceRef={columnVirtualizerInstanceRef}
128
+ />
129
+ );
130
+ ```
131
+
132
+ See the official TanStack [Virtualizer Instance API Docs](https://tanstack.com/virtual/v3/docs/api/virtualizer#virtualizer-instance) for more information.
133
+
134
+ ### Full Row and Column Virtualization Example
135
+
136
+ Try out the performance of the [fully virtualized example](/docs/examples/virtualized) with **10,000 rows** and over a dozen columns! Filtering, search, and sorting also maintain usable performance.
137
+
138
+ View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-virtualization)**
139
+
140
+ ### Headless Virtualization with MRT Hooks
141
+
142
+ If you are building a custom table in headless mode, you can still take advantage of some of the built-in virtualization functionality via the `useMRT_ColumnVirtualizer` and `useMRT_RowVirtualizer` hooks, which are wrappers for the TanStack Virtual `useVirtualizer` hook.
143
+
144
+ If you go this route, you will need to consult the [TanStack Virtual Docs](https://tanstack.com/virtual/v3) for more information on the exact styles and markup needed for the virtualization to work properly.
145
+
146
+ Here is the basics of how to use the MRT virtualization hooks:
147
+
148
+ ```tsx
149
+ import {
150
+ useMaterialReactTable,
151
+ useMRT_Rows,
152
+ useMRT_RowVirtualizer,
153
+ useMRT_ColumnVirtualizer,
154
+ } from 'material-react-table';
155
+
156
+ const table = useMaterialReactTable({
157
+ columns,
158
+ data,
159
+ enableColumnVirtualization: true,
160
+ enableRowVirtualization: true,
161
+ columnVirtualizerOptions: {
162
+ //...virtualizer options
163
+ },
164
+ rowVirtualizerOptions: {
165
+ //...virtualizer options
166
+ },
167
+ });
168
+
169
+ const rows = useMRT_Rows(table); //alternative to table.getRowModel()
170
+
171
+ const columnVirtualizer = useMRT_ColumnVirtualizer(table);
172
+ const rowVirtualizer = useMRT_RowVirtualizer(table);
173
+
174
+ //down in your row render
175
+ const virtualRows = rowVirtualizer.getVirtualItems();
176
+
177
+ virtualRows.map((virtualRow) => {
178
+ const row = rows[virtualRow.index];
179
+ return <Row key={row.id} />;
180
+ });
181
+ ```
182
+
183
+ Alternatively, just use the `useVirtualizer` hook directly from `@tanstack/react-virtual` if you want to build your own virtualization logic from scratch. The MRT hooks are provided as opinionated wrappers for your potential convenience.