Guides
Sticky Header/Footer Guide
How to use and customize the sticky header feature in Shadcn Table
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.
Example
Relevant Table Options
| Prop Name | Type | Description |
|---|---|---|
| enableStickyFooter | boolean | |
| enableStickyHeader | boolean | Keeps the header row in view while the body scrolls. The scroll box is capped by the --st-sticky-max-height CSS variable (70vh by default). Row virtualization turns it on. |
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.
A sticky header needs the table container to scroll vertically, so when it is on, the container's height is capped. The cap comes from the --st-sticky-max-height CSS variable and defaults to 70vh (70 percent of the window height). Users can also turn the sticky header on and off at runtime from the Sticky header row of the view settings panel; enableStickyHeader sets its starting value.
To change the cap, set the variable instead of a maxHeight style, for example with a Tailwind arbitrary property on the table layout (or on any ancestor element of the table). Set it to none when your page layout already limits the table's height.
<ShadcnTable
columns={columns}
data={data}
enableStickyHeader
stTableLayoutProps={{
className: '[--st-sticky-max-height:calc(100vh-12rem)]',
}}
/>Row virtualization forces the sticky header on. In that case the default cap is the full window height minus the toolbars (
clamp(350px, calc(100vh - toolbar height), 9999px)), so a virtualized table does not shrink to 70vh; the same--st-sticky-max-heightvariable overrides it. In full screen the table fills the window and the cap does not apply.
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.
<ShadcnTable columns={columns} data={data} enableStickyFooter />View Extra Storybook Examples