Shadcn React Table

Search documentation

Search the docs

Column pinning

Set enableColumnPinning: true to let users pin columns left or right from the column-actions menu. Pinned columns stay sticky while the table scrolls horizontally.

Column pinning
GitHub
ID
AvaThompsonOwnerEngineeringactive22Jan 2, 2023
0%
$45,000
LiamNguyenAdminMarketinginactive25Jan 13, 2023
9%
$47,137
NoahSilvaEditorDesignpending28Jan 24, 2023
18%
$49,274
EmmaCarterViewerSalesactive31Feb 4, 2023
27%
$51,411
OliviaRossiOwnerSupportinactive34Feb 15, 2023
36%
$53,548
WilliamWalkerAdminEngineeringpending37Feb 26, 2023
45%
$55,685
SophiaPatelEditorMarketingactive40Mar 9, 2023
54%
$57,822
JamesMullerViewerDesigninactive43Mar 20, 2023
63%
$59,959
IsabellaParkOwnerSalespending46Mar 31, 2023
72%
$62,096
LucasReyesAdminSupportactive49Apr 11, 2023
81%
$64,233
$4,120,536
Rows per page
1–10 of 48
const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  enableColumnPinning: true,
})

return <DataTable table={table} />

Initial pins

Pin columns from the start with initialState.columnPinning, grouping ids into left and right.

const table = useDataTable({
  data,
  columns,
  enableColumnPinning: true,
  initialState: {
    columnPinning: {
      left: ["firstName"],
      right: ["salary"],
    },
  },
})

Sticky positioning

Pinned columns rely on the same sticky behavior used elsewhere in the table. See the sticky guide for how that interacts with headers and footers.