Usage
import { easedColumns, SortableTable } from "@/components/eased/sortable-table/sortable-table";const col = easedColumns<Rep>();const columns = col.columns([ col.accessor("name", { header: "Rep", meta: { emphasis: true, grow: true } }), col.accessor("revenue", { header: "Revenue", sortDescFirst: true, meta: { align: "end" } }),]);<SortableTable label="Leaderboard" data={reps} columns={columns} getRowId={(r) => r.id} defaultSorting={[{ id: "revenue", desc: true }]} />When to use
- Leaderboards, pipelines, price lists and any table where people sort to answer a question, like "who closed the most this quarter".
- Tables of up to a few dozen rows, where watching rows move shows people what changed. Above 60 rows, rows reorder instantly by default.
When not to use
- When people reorder rows by hand. This table sorts by column values; it doesn't support dragging rows.
- Very large tables of thousands of rows. Sort them on the server and paginate.
How sorting works
- Hover or focus a sortable header and its arrow appears, showing the order a click will apply.
- Click once to sort ascending, again for descending, and a third time to clear the sort. Columns with
sortDescFirststart descending, which suits numbers like revenue where people want the biggest first. - Shift-click another header to add it as a secondary sort. Headers show numbers for the order the sorts apply in. Set
multiSort={false}to allow one sort at a time. - Set
allowUnsort={false}to skip the cleared state, so clicks only switch between ascending and descending. - Turn sorting off for a column with
enableSorting: falsein its column definition.
Controlled sorting
Pass sorting and onSortingChange to keep the sort in your own state, for example to save it in the URL. Use defaultSorting when the table should manage it after an initial order. Both use TanStack Table's SortingState, an array of { id, desc }.
Sortable Table vs the shadcn/ui Data Table
shadcn/ui's Data Table is a guide for building a table with TanStack Table yourself. Sorting is something you add: you enable the sorted row model and write a header button for each column that toggles its sort. When the order changes, the rows re-render in their new places at once.
Sortable Table starts where that guide ends:
| shadcn/ui Data Table | Eased Sortable Table | |
|---|---|---|
| Built on | TanStack Table | TanStack Table |
| Sorting | You add the sorted row model and header buttons | Built in on every column |
| Row movement | Rows jump to their new order | Rows glide to their new order on a spring |
| Sort by two columns | You wire it up | Shift-click, with numbered headers |
| Clearing a sort | You wire it up | Third click, optional |
| Sort arrow | You add an icon | Appears on hover and previews the next order |
| Reduced motion | Not applicable | Rows reorder instantly |
If you already have a shadcn/ui Data Table, the column definitions carry over: Sortable Table takes TanStack column definitions, with the easedColumns helper adding typed meta options for alignment and emphasis.
FAQ
How do I make a sortable table in React?
Use TanStack Table's sorting row model and toggle a column's sort when its header is clicked. Sortable Table does this for you on every column, with Shift-click for a second sort and rows that glide to their new order.
Can I sort by more than one column?
Yes. Click the first header, then Shift-click a second. The headers are numbered to show which sort applies first. Set multiSort={false} to allow only one.
Does Sortable Table support drag and drop reordering?
No. It sorts by the values in a column. For rows that people arrange by hand, use a drag and drop list instead.
What happens with reduced motion turned on?
Rows move to their new order instantly, with no glide.
Installation
pnpm dlx shadcn add @eased-pro/sortable-tablenpx shadcn add @eased-pro/sortable-tableyarn dlx shadcn add @eased-pro/sortable-tablebunx --bun shadcn add @eased-pro/sortable-tableInstalls from the @eased-pro registry and MCP server. · Already have Pro? Sign in.
Install the dependencies
pnpm add @tanstack/react-tablenpm install @tanstack/react-tableyarn add @tanstack/react-tablebun add @tanstack/react-tableAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Add the files
- components/eased/sortable-table/sortable-table.tsx
Source is included with Eased Pro. Members download the files with the CLI command above, or through the MCP server.
Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Props
Everything in Table, plus:
| Prop | Type | Default | |
|---|---|---|---|
sorting / defaultSorting | SortingState | [] | Controlled or uncontrolled. |
onSortingChange | (sorting) => void | ||
multiSort | boolean | true | Shift-click adds a secondary sort, numbered. |
allowUnsort | boolean | true | A third click clears the sort. |
flip | boolean | true | Rows glide to their new order. |
flipMaxRows | number | 60 | Above this, reorder instantly. |
Turn sorting off for a column with enableSorting: false. Start numeric columns descending with sortDescFirst.
Motion signature: the arrow stays hidden until you hover or focus a header, then previews the order a click will apply. On click, every row glides from where it was to its new place on the smooth spring while the arrow rotates on the same spring. Re-sorting mid-flight starts from where each row is. The header never shifts, and reduced motion reorders instantly.