Sticky Header and Footer Feature Guide
The sticky header and footer feature allows you to keep the header and footer of the table visible while scrolling through the table. This is useful when you have a large table and want to keep the header and footer visible at all times.
Relevant Table Options
Enable Sticky Header
Enabling the sticky header is as simple as setting the enableStickyHeader
table option to true
. This will make the header of the table stick to the top and remain visible while scrolling through the table.
When the sticky header is enabled, you will probably also want to give the table a maxHeight so that the table can scroll vertically and keep the header visible. You can do this by styling the table container with the muiTableContainerProps
table option.
If no maxHeight is specified, the table container will default to a
100vh
maxHeight whenenableStickyHeader
is enabled.
<MaterialReactTablecolumns={columns}data={data}enableStickyHeadermuiTableContainerProps={{ sx: { maxHeight: '500px' } }}/>
Enable Sticky Footer
Similarly, enabling the sticky footer is as simple as setting the enableStickyFooter
table option to true
. This will make the footer of the table stick to the bottom of the table and always be visible, even before the table is scrolled to the bottom.
<MaterialReactTable columns={columns} data={data} enableStickyFooter />
Enable Sticky Header and Footer Demo
First Name | Last Name | Email | City |
---|---|---|---|
Dylan | Murray | dmurray@yopmail.com | East Daphne |
Raquel | Kohler | rkholer33@yopmail.com | Columbus |
Ervin | Reinger | ereinger@mailinator.com | South Linda |
Brittany | McCullough | bmccullough44@mailinator.com | Lincoln |
Branson | Frami | bframi@yopmain.com | New York |
Ben | Murray | benm@email.com | Salt Lake City |
Elena | Smith | esmith@yopmail.com | Los Angeles |
Michael | Johnson | mjohnson@mailinator.com | Chicago |
Sophia | Brown | sbrown@yopmail.com | Houston |
Lucas | Davis | ldavis@mailinator.com | Phoenix |
Olivia | Garcia | ogarcia@yopmail.com | Philadelphia |
Liam | Rodriguez | lrodriguez@mailinator.com | San Antonio |
Emma | Martinez | emartinez@yopmail.com | San Diego |
Noah | Hernandez | nhernandez@mailinator.com | Dallas |
Ava | Lopez | alopez@yopmail.com | San Jose |
William | Gonzalez | wgonzalez@mailinator.com | Austin |
Isabella | Wilson | iwilson@yopmail.com | Jacksonville |
James | Anderson | janderson@mailinator.com | Fort Worth |
Mia | Thomas | mthomas@yopmail.com | Columbus |
Alexander | Taylor | ataylor@mailinator.com | Charlotte |
Grace | Moore | gmoore@yopmail.com | Indianapolis |
Ethan | White | ewhite@mailinator.com | San Francisco |
Lily | Harris | lharris@yopmail.com | Seattle |
Daniel | Martin | dmartin@mailinator.com | Denver |
Zoe | Jackson | zjackson@yopmail.com | Boston |
Matthew | Thompson | mthompson@mailinator.com | Nashville |
Ella | Garcia | egarcia@yopmail.com | Detroit |
David | Martinez | dmartinez@mailinator.com | Portland |
Aria | Robinson | arobinson@yopmail.com | Las Vegas |
Joseph | Clark | jclark@mailinator.com | Baltimore |
First Name | Last Name | City |
1import { useMemo } from 'react';2import {3 MaterialReactTable,4 useMaterialReactTable,5 type MRT_ColumnDef,6} from 'material-react-table';7import { data, type Person } from './makeData';89const Example = () => {10 const columns = useMemo<MRT_ColumnDef<Person>[]>(11 //column definitions...36 );3738 const table = useMaterialReactTable({39 columns,40 data,41 enableBottomToolbar: false,42 enableStickyHeader: true,43 enableStickyFooter: true,44 enablePagination: false,45 muiTableContainerProps: { sx: { maxHeight: '400px' } },46 muiTableBodyCellProps: {47 sx: (theme) => ({48 backgroundColor:49 theme.palette.mode === 'dark'50 ? theme.palette.grey[900]51 : theme.palette.grey[50],52 }),53 },54 });5556 return <MaterialReactTable table={table} />;57};5859export default Example;60
View Extra Storybook Examples