Skip to content

Commit 457ad60

Browse files
committed
release v2.2.0 - virtualization and row hooks
1 parent 9d33175 commit 457ad60

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

apps/material-react-table-docs/pages/changelog.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import Head from 'next/head';
1212

1313
### Version 2
1414

15+
#### Version 2.2.0 - 2024-01-01
16+
17+
- Added new `useMRT_Rows`, `useMRT_ColumnVirtualizer`, and `useMRT_RowVirtualizer` hooks to allow for more advanced use cases for headless mode.
18+
- Fixed possible duplicate table body row keys warning
19+
1520
#### Version 2.1.0 - 2023-12-22
1621

1722
- Upgraded to TanStack Table `v8.11.2` for new `columnResizeDirection` table option

apps/material-react-table-docs/pages/docs/guides/virtualization.mdx

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import EnableRowExample from '../../../examples/enable-row-virtualization';
44
import EnableColumnExample from '../../../examples/enable-column-virtualization';
55

66
<Head>
7-
<title>Virtualization Guide - Material React Table V2 Docs</title>
7+
<title>{'Virtualization Guide - Material React Table V2 Docs'}</title>
88
<meta
99
name="description"
1010
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
153153
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.
154154

155155
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()
187+
188+
const columnVirtualizer = useMRT_ColumnVirtualizer(table);
189+
const rowVirtualizer = useMRT_RowVirtualizer(table);
190+
191+
//down in your row render
192+
const virtualRows = rowVirtualizer.getVirtualItems();
193+
194+
virtualRows.map((virtualRow) => {
195+
const row = rows[virtualRow.index];
196+
return <Row key={row.id} />;
197+
});
198+
```
199+
200+
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.

packages/material-react-table/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.1.0",
2+
"version": "2.2.0",
33
"license": "MIT",
44
"name": "material-react-table",
55
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",

0 commit comments

Comments
 (0)