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 {3 MaterialReactTable,4 useMaterialReactTable,5 type MRT_Virtualizer,6} from 'material-react-table';7import { fakeColumns, fakeData } from './makeData';89const Example = () => {10 //optionally access the underlying virtualizer instance11 const columnVirtualizerInstanceRef =12 useRef<MRT_Virtualizer<HTMLDivElement, HTMLTableCellElement>>(null);1314 const table = useMaterialReactTable({15 columnVirtualizerInstanceRef, //optional16 columnVirtualizerOptions: { overscan: 4 }, //optionally customize the virtualizer17 columns: fakeColumns, //500 columns18 data: fakeData,19 enableColumnVirtualization: true,20 enableColumnPinning: true,21 enableRowNumbers: true,22 });2324 return <MaterialReactTable table={table} />;25};2627export default Example;28
View Extra Storybook Examples