MRT logoMaterial React Table

Row Virtualization Example

Material React Table has a built-in row virtualization feature (via @tanstack/react-virtual) that allows you to render a large number of rows 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! 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
1AbrahamNoraHodkiewiczMonique61@gmail.com174 Cronin Summit92122-0996JakaylaportNew HampshireCambodia
2AldaGeorgeMayertEdwardo27@gmail.com97934 Roman Road30009JohathanmouthWashingtonEcuador
3JulienLinaThielMaureen.Schuster@hotmail.com6664 Damon Pines14117-1951South LeonsideIllinoisWallis and Futuna
4QueenHaydenO'ReillyLily20@yahoo.com15541 Kulas Brooks47763Port AlbertbergWashingtonMicronesia
5ElenaYasmineJohnstonNestor.Cummings@gmail.com33300 S Main Street36471SonyaburghMississippiBouvet Island
6LynnBriceFritschGrayson.Shields@yahoo.com9632 Upton Terrace44893North SashabergMaineIraq
7EdwinaMelissaReingerKarlee86@hotmail.com4773 Hoeger Stream87028OlenfortWyomingAmerican Samoa
8VaughnEasterJakubowskiMikayla.Klocko@gmail.com8635 E 9th Street91321MyramouthIndianaSaint Barthelemy
9RoyceSandraToyKyleigh_Conn@gmail.com3203 Cormier Groves32432MiramarMinnesotaIreland
10ShanieFloDibbertGunnar83@hotmail.com594 Pacocha Club24613KosstonUtahLiechtenstein
11JocelynNyaDenesikLauren_Koss@hotmail.com3717 Old Lane09429-5982North KaitlyntownNevadaSaint Helena
12WaylonCraigConnAdrian83@yahoo.com615 Madge River49651-9976South ColtenIowaYemen
13DonnellFrederikKonopelskiKoby.Schroeder@yahoo.com797 Waters Courts01782-1522MannburghNew JerseyMozambique
14MacyRaymondNikolausBen.Cormier36@hotmail.com13251 Marcella Ports49010Lake RosellaboroughSouth DakotaGreenland
15DaijaCarolineFramiMollie_Torphy45@hotmail.com728 Kreiger Manor29028New ForestfurtWisconsinHoly See (Vatican City State)
16DavonteRoslynKoelpinAnnie_Hudson35@yahoo.com997 Hipolito Lodge69123-2706East AnaisfurtSouth CarolinaBouvet Island

Source Code

1import { useEffect, useMemo, useRef, useState } from 'react';
2import {
3 MaterialReactTable,
4 useMaterialReactTable,
5 type MRT_ColumnDef,
6 type MRT_SortingState,
7 type MRT_RowVirtualizer,
8} from 'material-react-table';
9import { makeData, type Person } from './makeData';
10
11const Example = () => {
12 const columns = useMemo<MRT_ColumnDef<Person>[]>(
13 //column definitions...
58 );
59
60 //optionally access the underlying virtualizer instance
61 const rowVirtualizerInstanceRef = useRef<MRT_RowVirtualizer>(null);
62
63 const [data, setData] = useState<Person[]>([]);
64 const [isLoading, setIsLoading] = useState(true);
65 const [sorting, setSorting] = useState<MRT_SortingState>([]);
66
67 useEffect(() => {
68 if (typeof window !== 'undefined') {
69 setData(makeData(10_000));
70 setIsLoading(false);
71 }
72 }, []);
73
74 useEffect(() => {
75 //scroll to the top of the table when the sorting changes
76 try {
77 rowVirtualizerInstanceRef.current?.scrollToIndex?.(0);
78 } catch (error) {
79 console.error(error);
80 }
81 }, [sorting]);
82
83 const table = useMaterialReactTable({
84 columns,
85 data, //10,000 rows
86 enableBottomToolbar: false,
87 enableGlobalFilterModes: true,
88 enablePagination: false,
89 enableRowNumbers: true,
90 enableRowVirtualization: true,
91 muiTableContainerProps: { sx: { maxHeight: '600px' } },
92 onSortingChange: setSorting,
93 state: { isLoading, sorting },
94 rowVirtualizerInstanceRef, //optional
95 rowVirtualizerOptions: { overscan: 5 }, //optionally customize the row virtualizer
96 });
97
98 return <MaterialReactTable table={table} />;
99};
100
101export default Example;
102

View Extra Storybook Examples