Guides
Column Pinning Guide
How to use and customize the column pinning features of Shadcn Table
Column pinning lets users pin (freeze) columns to the start or end of the table (left and right in a left-to-right layout). Pinned columns do not scroll horizontally with the rest of the columns, so they always stay visible to the user. Column pinning is on by default: the column menu has Pin to start, Pin to end and Unpin items.
Example
Relevant Table Options
| Prop Name | Type | Description |
|---|---|---|
| enableColumnPinning | boolean | Adds the pin items to the column menu (Pin to start, Pin to end, Unpin). Set it to false to turn column pinning off. |
| onColumnPinningChange | OnChangeFn<ColumnPinningState> | If provided, this function will be called with an updaterFn when state.columnPinning changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table. |
Relevant Column Options
| Column Option | Type | Description |
|---|---|---|
| enablePinning | boolean |
Relevant State
| State Option | Type | Description |
|---|---|---|
| columnPinning | { start: Array<string>, end: Array<string> } | an object with start and end properties, each of which is an array of strings representing the columns that are pinned to the start (left in LTR) or end (right in LTR) side of the table |
Turn Column Pinning Off
Column pinning is enabled by default. Set the enableColumnPinning table option to false to remove the pin items from the column menu. To keep one column from being pinned, set enablePinning: false in its column definition.
const table = useShadcnTable({
data,
columns,
enableColumnPinning: false,
});
return <ShadcnTable table={table} />;Pin (Freeze) Columns By Default
Columns can start out pinned in your table by setting the columnPinning states in initialState or state. The pinning sides are start and end.
const table = useShadcnTable({
data,
columns,
initialState: { columnPinning: { start: ['email'] } }, //pin email column to the start (left in LTR) by default
});
return <ShadcnTable table={table} />;When enableRowActions is on, the row actions column is pinned to the end by default. That default applies only while you give no columnPinning of your own, so include 'st-row-actions' in end if you set columnPinning and still want it pinned. See the Row Actions Guide.
Pinned Column Widths and the Edge Shadow
In the default 'grid' layout, pinned columns keep their set width while the other data columns share the spare width, so a pinned column never changes width while the table scrolls.
The pinned cells on the inner edge of each side, header and body, cast a small shadow towards the scrolling columns while that side has pinned columns. The shadow color comes from the --st-edge-shadow variable, see the Tint Tokens Guide. When columns are hidden behind the scrolled edge, a scroll chevron shows in the header row on hover, see the Scroll Cues Guide.
View Extra Storybook Examples