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 Props
Enable Sticky Header
Enabling the sticky header is as simple as setting the enableStickyHeader
prop 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
prop.
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
prop 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 |
Kevin | Klein | kklien@mailinator.com | Nebraska |
First Name | Last Name | City |
1import React, { useMemo } from 'react';2import { MaterialReactTable, type MRT_ColumnDef } from 'material-react-table';3import { data, type Person } from './makeData';45const Example = () => {6 const columns = useMemo<MRT_ColumnDef<Person>[]>(7 () => [8 {9 accessorKey: 'firstName',10 header: 'First Name',11 footer: 'First Name',12 },13 {14 accessorKey: 'lastName',15 header: 'Last Name',16 footer: 'Last Name',17 },18 {19 accessorKey: 'email',20 header: 'Email',21 footer: 'Email',22 },23 {24 accessorKey: 'city',25 header: 'City',26 footer: 'City',27 },28 ],29 [],30 );3132 return (33 <MaterialReactTable34 columns={columns}35 data={data}36 enableStickyHeader37 enableStickyFooter38 muiTableContainerProps={{ sx: { maxHeight: '300px' } }}39 />40 );41};4243export default Example;44
View Extra Storybook Examples