ExamplesColumns & Pinning
Custom headers
ReactNode headers with live sort-state icons (string headers still work).
ColumnDef.header accepts a component, not just a string. The header subscribes to live grid
state and re-renders when it changes. In sort header-click mode a custom header owns its own
display: the built-in sort arrow is only appended to string headers.
Click the Name or Score header to sort: a minus means unsorted, an up icon ascending, a down icon descending.
pnpm dlx shadcn@latest add @gridcn/data-grid-custom-headers-demo
What's in the demo
header: <span>ā¦</span>: ReactNode headers on Name and ScoreuseDataGridSortState(): the live sort spec list. The icon follows unsorted ā asc ā descheaderText: "Name": the accessible/aria text whenheaderis not a plain string- Email stays a string header and gets the built-in sort arrow appended
Behavior reference
- Custom headers: when to use a component header and the
headerTextcontract
Related
- Pinning: the built-in header menu on string headers