Shadcn React Table

Search documentation

Search the docs

Column resizing

Set enableColumnResizing: true to add a drag handle on each column's edge. Users drag the handle to widen or narrow a column.

Column resizing
GitHub
ID
AvaThompsonOwnerEngineeringactive22$45,000Jan 2, 2023
0%
LiamNguyenAdminMarketinginactive25$47,137Jan 13, 2023
9%
NoahSilvaEditorDesignpending28$49,274Jan 24, 2023
18%
EmmaCarterViewerSalesactive31$51,411Feb 4, 2023
27%
OliviaRossiOwnerSupportinactive34$53,548Feb 15, 2023
36%
WilliamWalkerAdminEngineeringpending37$55,685Feb 26, 2023
45%
SophiaPatelEditorMarketingactive40$57,822Mar 9, 2023
54%
JamesMullerViewerDesigninactive43$59,959Mar 20, 2023
63%
IsabellaParkOwnerSalespending46$62,096Mar 31, 2023
72%
LucasReyesAdminSupportactive49$64,233Apr 11, 2023
81%
$4,120,536
Rows per page
1–10 of 48
const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  enableColumnResizing: true,
})

return <DataTable table={table} />

Resize mode

The resize mode defaults to "onChange", so columns resize live as the handle moves. Pass TanStack's columnResizeMode: "onEnd" to defer the resize until the handle is released.

const table = useDataTable({
  data,
  columns,
  enableColumnResizing: true,
  columnResizeMode: "onEnd",
})

Width constraints

Column widths come from size, minSize, and maxSize on the column definition.

const columns = [
  { accessorKey: "firstName", size: 200, minSize: 120, maxSize: 320 },
]

Set sensible bounds

Define minSize and maxSize so users cannot collapse or stretch a column past a usable width.

Auto-sizing

Double-click a column's resize handle to size it to fit its widest value — header and data, across the full dataset (not just the rows currently on screen). This is on by default whenever enableColumnResizing is set, and respects each column's minSize/maxSize bounds.

Set enableColumnAutosize: false to turn it off; double-clicking the handle then resets the column to its default size instead.

const table = useDataTable({
  data,
  columns,
  enableColumnResizing: true,
  enableColumnAutosize: true, // default: matches enableColumnResizing
})

You can also trigger it imperatively from the table instance:

table.cnTable.autoSizeColumn("firstName")
table.cnTable.autoSizeAllColumns()