MRT logoMaterial React Table

Column Virtualization Example

Material React Table has a built-in column virtualization feature (via @tanstack/react-virtual) that allows you to render a large number of columns without major performance issues that you would normally see with a large number of DOM elements.

Try out the performance of the table below with 500 columns! Filtering, Search, and Sorting also maintain usable performance.

Be sure to also check out the full virtualization feature guide docs to learn about both Row and Column Virtualization.

NOTE: You should only enable row virtualization if you have a large number of rows or columns. Depending on the size of the table, if you are rendering fewer 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 over 50 rows or so at the same time with no pagination or dozens of columns.

More Examples

Demo

Open StackblitzOpen Code SandboxOpen on GitHub
1-10 of 10

Source Code

1import { useRef } from 'react';
2import { MaterialReactTable, type MRT_Virtualizer } from 'material-react-table';
3import { fakeColumns, fakeData } from './makeData';
4
5const Example = () => {
6 //optionally access the underlying virtualizer instance
7 const columnVirtualizerInstanceRef =
8 useRef<MRT_Virtualizer<HTMLDivElement, HTMLTableCellElement>>(null);
9
10 return (
11 <MaterialReactTable
12 columnVirtualizerInstanceRef={columnVirtualizerInstanceRef} //optional
13 columnVirtualizerOptions={{ overscan: 4 }} //optionally customize the virtualizer
14 columns={fakeColumns} //500 columns
15 data={fakeData}
16 enableColumnVirtualization
17 enableColumnPinning
18 enableRowNumbers
19 />
20 );
21};
22
23export default Example;
24

View Extra Storybook Examples