Sortable table

Free

Records in columns: click a header and the rows glide into order, numbers line up at the end, and picked rows raise a bulk bar that counts them. Airy in lively, compact lines in quiet.

npx shadcn@latest add https://pixilui.com/r/sortable-table.json

Preview

Click a header and rows glide into order; pick rows and the bulk bar rises.
Select

When to use

Use it when

  • Invoices, members, deals: records with the same few fields, sorted by any of them.
  • Acting on several records at once: selectable, with bulk actions (Mark as paid, Download).

Use something else when

  • A list of runs or logs: use list rows (one mark, a title, one line, one time).
  • A box inside a card around the table, or two line weights: the lock leaves both out.
  • Thousands of rows: page them; the table renders every row.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/sortable-table.json

Adds sortable-table.tsx with checkbox.tsx, field.tsx and list-row.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { SortableTable } from "@/components/pixilui/sortable-table";

<SortableTable
  aria-label={aria-label}
  columns={columns}
  rows={rows}
  onSortChange={onSortChange}
  onSelectedChange={onSelectedChange}
/>

Fills its container; give each column a track ("minmax(0, 1fr)", "120px"). Every cell is at least a row tall, so nothing inside can unstretch it.

API reference

PropTypeDefault
aria-labelRequiredstring–The table's accessible name ("Invoices").
columnsRequiredSortableTableColumn[]NONEThe columns, in order.
rowsRequiredSortableTableRow[]NONEThe rows, in their resting order.
sortSortableTableSort | null–The sort, controlled. Pair with onSortChange.
defaultSortSortableTableSort | nullnullThe sort at first, uncontrolled.
onSortChange(sort: SortableTableSort) => void–Runs when a header sorts the table.
selectableboolean–A check column that picks rows.

Also takes every native <div> attribute, and a ref.

Keyboard

TabReaches each sortable header, then each row's check box.
Enter SpaceOn a header: sorts by it (instantly, from the keyboard). On a check box: picks the row.

Accessibility

  • table, rowgroup, row, columnheader and cell roles; a sorted header carries aria-sort.
  • The header check box reads true, false or mixed; a picked row is aria-selected; the bulk bar is a named toolbar with a live count.
  • An actions column names itself for screen readers (srLabel).

Motion

  • A header click glides the rows to their new places (the system's flip, 420ms); from the keyboard the reorder is instant.
  • The sort arrow shows on hover and stays once sorted; hover washes a row in 150ms.
  • The bulk bar rises from the foot as the first row is picked and leaves with the last.
  • A removed row fades into a blur, then the rest glide up to close the gap; Load more's rows arrive 35ms apart while the body glides taller.
  • Reduced motion: every change instant.

PixilUI Pro opens soon. The first 20 licenses are $99.