Shadcn React Table

Search documentation

Search the docs

Column ordering

Set enableColumnOrdering: true to add a drag grip to each header. Users can grab the grip and drag a column to a new position.

Column orderingDrag column headers to reorder.
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
tsx
const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  enableColumnOrdering: true,
})

return <DataTable table={table} />

While you drag

The whole column moves with its header — body, filter and footer cells included — and the other columns slide aside to show where it will land. The movement comes from CSS variables on the scroll surface, so dragging doesn't re-render any rows. With "reduce motion" turned on in the operating system, the columns move without the slide animation.

Column dragThe whole column moves while you drag it.
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%
$4,120,536
Rows per page
1–8 of 48

Initial order

Provide the starting order with initialState.columnOrder, an array of column ids.

tsx
const table = useDataTable({
  data,
  columns,
  enableColumnOrdering: true,
  initialState: {
    columnOrder: ["firstName", "lastName", "salary"],
  },
})

Pair with pinning

Pinned columns stay anchored while the rest reorder. Combine ordering with pinning to keep key columns in view.