You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<title>Virtualization Guide - Material React Table V2 Docs</title>
7
+
<title>{'Virtualization Guide - Material React Table V2 Docs'}</title>
8
8
<meta
9
9
name="description"
10
10
content="How to virtualize rows and columns in Material React Table to improve performance and user experience when there are a lot of rows or a lot of columns in the table."
@@ -153,3 +153,48 @@ See the official TanStack [Virtualizer Instance API Docs](https://tanstack.com/v
153
153
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.
154
154
155
155
View Extra Storybook **[Examples](https://www.material-react-table.dev/?path=/story/features-virtualization)**
156
+
157
+
### Headless Virtualization with MRT Hooks
158
+
159
+
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.
160
+
161
+
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.
162
+
163
+
Here is the basics of how to use the MRT virtualization hooks:
164
+
165
+
```tsx
166
+
import {
167
+
useMaterialReactTable,
168
+
useMRT_Rows,
169
+
useMRT_RowVirtualizer,
170
+
useMRT_ColumnVirtualizer,
171
+
} from'material-react-table';
172
+
173
+
const table =useMaterialReactTable({
174
+
columns,
175
+
data,
176
+
enableColumnVirtualization: true,
177
+
enableRowVirtualization: true,
178
+
columnVirtualizerOptions: {
179
+
//...virtualizer options
180
+
},
181
+
rowVirtualizerOptions: {
182
+
//...virtualizer options
183
+
},
184
+
});
185
+
186
+
const rows =useMRT_Rows(table); //alternative to table.getRowModel()
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.
0 commit comments