DocsGuides

Guides

Column Pinning Guide

How to use and customize the column pinning features of Shadcn Table

Column pinning is a cool feature that lets users pin (freeze) columns to the left or right of the table. Pinned columns will not scroll horizontally with the rest of the columns so that they always stay visible to the user.

Relevant Table Options

#
Prop Name
Type
Default Value
More Info Links
1boolean
2OnChangeFn<ColumnPinningState>TanStack Table Column Pinning Docs

Relevant Column Options

#
Column Option
Type
Default Value
More Info Links
1boolean

Relevant State

#
State Option
Type
Default Value
More Info Links
1{ start: Array<string>, end: Array<string> }{ left: [], right: [] }TanStack Table Column Pinning Docs

Enable Column Pinning

Column pinning can simply be enabled by setting the enableColumnPinning table option to true.

const table = useShadcnTable({
  data,
  columns,
  enableColumnPinning: true,
});

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.

const table = useShadcnTable({
  data,
  columns,
  enableColumnPinning: true,
  initialState: { columnPinning: { start: ['email'] } }, //pin email column to the start (left in LTR) by default
});

return <ShadcnTable table={table} />;

Apply Absolute Column Widths

You might consider using the layoutMode: 'grid-no-grow' table option to give all columns an exact width if you don't want the columns collapsing a little while scrolling. Some people like this subtle behavior, but others do not.

const table = useShadcnTable({
  data,
  columns,
  enableColumnPinning: true,
  layoutMode: 'grid-no-grow',
});

return <ShadcnTable table={table} />;

Column Pinning Example

Loading example

View Extra Storybook Examples

On this page