MRT logoMaterial React Table

Virtualized Example

Material React Table has a built-in virtualization features (via @tanstack/react-virual) that allows you to render a large number of rows or 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 10,000 rows and over a dozen 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








1XavierDarrenQuitzonVernon27@hotmail.com251.498.0403371 Runolfsson Crescent41862-9310
2AllenHerminioKunzeTheo_Bogisich@yahoo.com(311) 978-1180 x883556901 Stevie Route44239-8785
3CurtisDaphneBartonCristian80@yahoo.com908.439.0834213 Bahringer Village13484-6407
4QuentinMillieWymanJanick_Pagac@hotmail.com(666) 988-6971 x56120477 Hipolito Freeway85768-4262
5JaydeEleanoreO'ConnerGia_Roberts38@hotmail.com(529) 494-81919417 S Front Street12701-8184
6FinnMaeganSanfordSonia.Kunze@yahoo.com1-781-203-4496 x6913755 Woodlands Road20957-0130
7DomenicDedricLubowitzShaylee.Dare60@gmail.com779.489.7127 x402159559 School Close36628-0879
8ArloNathanaelLueilwitzLiliane_Dibbert@yahoo.com556-830-6546 x20077237 Kovacek Run78416
9EduardoAdrianaBlockMertie65@gmail.com355-964-2904 x4758639 Main Street E93430
10AbdielGretchenGorczanySchuyler_Abernathy@hotmail.com(448) 386-5607 x2547627927 E 4th Avenue71027-1755
11CarloHoustonVonRuedenRonny_Hartmann@hotmail.com686.445.9724 x70485615 Franklin Road28636
12DevonteMichaelaNitzscheKailyn_Sawayn11@gmail.com(355) 644-7383602 Goodwin Haven62898-3622
13CatharineAndreDeckowFrederick_Feil@yahoo.com424.803.3557 x436147782 10th Street24452-0786
14HoseaHattieSwaniawskiCorbin.Ruecker71@hotmail.com531.982.42728661 Kristy Bypass10772
15TerranceKaydenGoodwinElliot42@hotmail.com1-966-371-5840 x28940029 Hyatt Springs51032-7894
16LoyalTrinityWolffDelphia36@hotmail.com1-988-655-3181 x2137425686 Ash Close18208-9186
17LincolnKevonBaumbachChauncey_Miller-Dickens85@gmail.com(593) 562-3964 x047283292 10th Street88717-1497

Source Code

1import { useEffect, useMemo, useRef, useState } from 'react';
2import {
3 MaterialReactTable,
4 type MRT_ColumnDef,
5 type MRT_SortingState,
6 type MRT_Virtualizer,
7} from 'material-react-table';
8import { makeData, type Person } from './makeData';
9
10const Example = () => {
11 const columns = useMemo<MRT_ColumnDef<Person>[]>(
12 //column definitions...
89 );
90
91 //optionally access the underlying virtualizer instance
92 const rowVirtualizerInstanceRef =
93 useRef<MRT_Virtualizer<HTMLDivElement, HTMLTableRowElement>>(null);
94
95 const [data, setData] = useState<Person[]>([]);
96 const [isLoading, setIsLoading] = useState(true);
97 const [sorting, setSorting] = useState<MRT_SortingState>([]);
98
99 useEffect(() => {
100 if (typeof window !== 'undefined') {
101 setData(makeData(10_000));
102 setIsLoading(false);
103 }
104 }, []);
105
106 useEffect(() => {
107 //scroll to the top of the table when the sorting changes
108 try {
109 rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
110 } catch (error) {
111 console.error(error);
112 }
113 }, [sorting]);
114
115 return (
116 <MaterialReactTable
117 columns={columns}
118 data={data} //10,000 rows
119 defaultDisplayColumn={{ enableResizing: true }}
120 enableBottomToolbar={false}
121 enableColumnResizing
122 enableColumnVirtualization
123 enableGlobalFilterModes
124 enablePagination={false}
125 enableColumnPinning
126 enableRowNumbers
127 enableRowVirtualization
128 muiTableContainerProps={{ sx: { maxHeight: '600px' } }}
129 onSortingChange={setSorting}
130 state={{ isLoading, sorting }}
131 rowVirtualizerInstanceRef={rowVirtualizerInstanceRef} //optional
132 rowVirtualizerOptions={{ overscan: 5 }} //optionally customize the row virtualizer
133 columnVirtualizerOptions={{ overscan: 2 }} //optionally customize the column virtualizer
134 />
135 );
136};
137
138//virtualizerInstanceRef was renamed to rowVirtualizerInstanceRef in v1.5.0
139//virtualizerProps was renamed to rowVirtualizerOptions in v1.5.0
140
141export default Example;
142

View Extra Storybook Examples