For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
Shadcn Labs/

Sortable Table

A data table with sortable columns and search. Rows glide to their new positions. A React component built on View Transitions, installed with the shadcn CLI.

Largest US tech stocks
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-table

Usage

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

PropTypeDefaultDescription
columnsSortableTableColumn<Row>[]-Column definitions rendered in the header and cells.
rowsRow[] (each row needs an id: string | number)-Data rows, each with a unique id used as the transition key.
sortSortableTableSort | null-Controlled sort state, or null for the original order.
defaultSortSortableTableSort | nullnullInitial sort state when uncontrolled.
onSortChange(sort: SortableTableSort | null) => void-Called with the next sort after a header click.
searchablebooleanfalseShows a search field above the table.
querystring-Controlled search query.
defaultQuerystring""Initial query when uncontrolled.
onQueryChange(query: string) => void-Called with the next query on every keystroke.
searchFn(row: Row, query: string) => booleanany columnDecides which rows match; defaults to a case-insensitive match on any column.
searchPlaceholderstring"Search…"Placeholder and accessible label for the search field.
captionReactNode-Accessible table name, rendered as a visually hidden <caption>.
emptyMessageReactNode"No results."Content shown when no rows are visible.

SortableTableColumn

FieldTypeDefaultDescription
keystring-Unique column id, also the default field read from each row.
headerReactNode-Content rendered in the column header button.
labelstringheaderPlain-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) => ReactNodevalueCustom cell content; defaults to the accessor value.
sortFn(a: Row, b: Row) => number-Custom comparator; should return the ascending order, descending reverses it.
sortablebooleantrueWhether the column header shows a sort button.
align"left" | "center" | "right""left"Text alignment for the header and cells.
widthnumber | string-Column width; columns without one share the rest.
classNamestring-Applied to the header and every cell of the column.

SortableTableSort

FieldTypeDescription
keystringKey of the column being sorted.
direction"asc" | "desc"Sort direction for that column.