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.
1import { useRef } from 'react';2import { MaterialReactTable, type MRT_Virtualizer } from 'material-react-table';3import { fakeColumns, fakeData } from './makeData';45const Example = () => {6 //optionally access the underlying virtualizer instance7 const columnVirtualizerInstanceRef =8 useRef<MRT_Virtualizer<HTMLDivElement, HTMLTableCellElement>>(null);910 return (11 <MaterialReactTable12 columnVirtualizerInstanceRef={columnVirtualizerInstanceRef} //optional13 columnVirtualizerOptions={{ overscan: 4 }} //optionally customize the virtualizer14 columns={fakeColumns} //500 columns15 data={fakeData}16 enableColumnVirtualization17 enableColumnPinning18 enableRowNumbers19 />20 );21};2223export default Example;24
View Extra Storybook Examples