Components
- Accordion
- Add to Cart
- Animated List
- Carousel
- Collapsible Sidebarnew
- Dynamic Island
- Expandable Cardnew
- Expanding Searchnew
- Filter Grid
- Kanban Board
- Layout Switcher
- Morphing Popover
- Number Flip
- Page Transition
- Product Gallery
- Segmented Control
- Sortable Table
- Stack Navigator
- Status Button
- Step Wizard
- Tabs
- Text Morphnew
- Theme Mode Switch
- Theme Morph Button
- Theme Toggle Button
- Theme Toggle Switch
- Theme Transition
- Toast Stacknew
| AAPLApple | $227.48 | +1.84% | $3.42T |
| MSFTMicrosoft | $418.16 | -0.62% | $3.11T |
| NVDANVIDIA | $121.40 | +3.27% | $2.98T |
| GOOGLAlphabet | $165.86 | +0.38% | $2.04T |
| AMZNAmazon | $186.51 | -1.45% | $1.96T |
| METAMeta | $582.77 | +2.06% | $1.47T |
| AVGOBroadcom | $175.32 | +0.12% | $0.82T |
| TSLATesla | $249.83 | -2.91% | $0.79T |
8 rows, sorted by Mkt cap, descending
Installation
$ pnpm dlx shadcn@latest add @transition-kit/sortable-tableUsage
import { SortableTable } from "@/components/transitions/sortable-table";
import type { SortableTableColumn } from "@/components/transitions/sortable-table";interface Member {
id: string;
name: string;
role: string;
commits: number;
}
const columns: SortableTableColumn<Member>[] = [
{ key: "name", header: "Name", width: "40%" },
{ key: "role", header: "Role" },
{ key: "commits", header: "Commits", align: "right" },
];
<SortableTable
caption="Team members"
columns={columns}
rows={members}
defaultSort={{ key: "commits", direction: "desc" }}
searchable
/>;API Reference
SortableTable
| Prop | Type | Default | Description |
|---|---|---|---|
columns | SortableTableColumn<Row>[] | - | Column definitions rendered in the header and cells. |
rows | Row[] (each row needs an id: string | number) | - | Data rows, each with a unique id used as the transition key. |
sort | SortableTableSort | null | - | Controlled sort state, or null for the original order. |
defaultSort | SortableTableSort | null | null | Initial sort state when uncontrolled. |
onSortChange | (sort: SortableTableSort | null) => void | - | Called with the next sort after a header click. |
searchable | boolean | false | Shows a search field above the table. |
query | string | - | Controlled search query. |
defaultQuery | string | "" | Initial query when uncontrolled. |
onQueryChange | (query: string) => void | - | Called with the next query on every keystroke. |
searchFn | (row: Row, query: string) => boolean | any column | Decides which rows match; defaults to a case-insensitive match on any column. |
searchPlaceholder | string | "Search…" | Placeholder and accessible label for the search field. |
caption | ReactNode | - | Accessible table name, rendered as a visually hidden <caption>. |
emptyMessage | ReactNode | "No results." | Content shown when no rows are visible. |
SortableTableColumn
| Field | Type | Default | Description |
|---|---|---|---|
key | string | - | Unique column id, also the default field read from each row. |
header | ReactNode | - | Content rendered in the column header button. |
label | string | header | Plain-text column name for announcements when header is not a string. |
accessor | (row: Row) => string | number | Date | … | row[key] | Value used to sort and search. Numbers and dates compare numerically, strings with a locale-aware natural collator, and empty values sort last. |
cell | (row: Row) => ReactNode | value | Custom cell content; defaults to the accessor value. |
sortFn | (a: Row, b: Row) => number | - | Custom comparator; should return the ascending order, descending reverses it. |
sortable | boolean | true | Whether the column header shows a sort button. |
align | "left" | "center" | "right" | "left" | Text alignment for the header and cells. |
width | number | string | - | Column width; columns without one share the rest. |
className | string | - | Applied to the header and every cell of the column. |
SortableTableSort
| Field | Type | Description |
|---|---|---|
key | string | Key of the column being sorted. |
direction | "asc" | "desc" | Sort direction for that column. |