Usage
useTableSortable adds the header sort controls but does not reorder the rows: pass rows that are already sorted as data, sorted by you from the sort state or by useTableSortableState. T is the row type; TypeScript cannot infer it from the config, so it defaults to Record<string, unknown>, which a Table with typed rows rejects: pass it, as in useTableSortable<Walk>(…) for <Table<Walk>>. When the sort keys have a narrower type than string (a union, or keys that useTableSortableState infers from defaultSort), pass both: useTableSortable<Walk, WalkSortKey>(…). Call it with a config object containing the sort state and callback, and pass the returned plugin to Table via the plugins prop.
tsimport {useTableSortable} from '@astryxdesign/core/Table'
Parameters
| Param | Type | Description |
|---|---|---|
sortrequired | Array<{sortKey: TSortKey, direction: 'ascending' | 'descending'}> | Current sort state that the headers show; the plugin does not reorder data, so sort your rows from this value (TableSortState<TSortKey>). Ordered array of entries; the first is the primary sort, the rest are tiebreakers. An empty array means unsorted. Direction is the full word: 'ascending' / 'descending', not 'asc' / 'desc'. |
onSortChangerequired | (sort: Array<{sortKey: TSortKey, direction: 'ascending' | 'descending'}>) => void | Called with the next sort state when the user clicks a sortable header; store it and sort your data from it, because the plugin does not reorder rows. |
allowUnsortedState | boolean (default: true) | Allow cycling back to unsorted. When true: 'ascending', 'descending', unsorted. When false: 'ascending', 'descending', 'ascending'. |
isMultiSortEnabled | boolean (default: false) | Enable multi-sort via Shift+click. Regular click still replaces the entire sort state. |
Examples
Common configurations, variations, and states.Table with sortable columns, click headers to sort ascending or descending.
Use with shadcn
Already using the shadcn registry workflow? Install the real Astryx package and a local public re-export. Component implementation source stays in Astryx.
This install URL expires with the draft preview.bashnpx shadcn@4.19.0 add https://astryx-c01x1j3kn-fbopensource.vercel.app/shadcn/hooks/use-table-sortable.json