Sort header
In code: SortHeader
A column heading that sorts the table when pressed
Preview
| 2026-11-14 | Otis Brandt | £45.50 |
| 2026-11-13 | Mira Kovac | £80.00 |
| 2026-11-12 | Noor Haddad | £120.00 |
Use
The code of the preview above
import { SortHeader, Table } from '@/components/ui';
function SortHeaderDemo() {
const [by, setBy] = useState<'date' | 'who' | 'amount'>('date');
const [dir, setDir] = useState<'ascending' | 'descending'>('descending');
const rows = [...PAYMENTS].sort((a, b) => (a[by] < b[by] ? -1 : a[by] > b[by] ? 1 : 0) * (dir === 'ascending' ? 1 : -1));
const sort = (key: typeof by) => () => {
setDir(by === key && dir === 'descending' ? 'ascending' : 'descending');
setBy(key);
};
return (
<div className="ui-grow">
<Table scroll>
<thead>
<tr>
<SortHeader direction={by === 'date' ? dir : undefined} onSort={sort('date')}>Date</SortHeader>
<SortHeader direction={by === 'who' ? dir : undefined} onSort={sort('who')}>Customer</SortHeader>
<SortHeader className="ui-num" direction={by === 'amount' ? dir : undefined} onSort={sort('amount')}>Amount</SortHeader>
</tr>
</thead>
<tbody>
{rows.map((row) => (
<tr key={row.date}>
<td className="ui-mono">{row.date}</td>
<td>{row.who}</td>
<td className="ui-num">£{row.amount.toFixed(2)}</td>
</tr>
))}
</tbody>
</Table>
</div>
);
}Options
| Option | Type | What it does |
|---|---|---|
direction | "ascending" | "descending" | How the table is sorted by this column now. |
onSort | () => void | Runs when the heading is pressed; change the sort and pass the new direction. |
It also takes the 285 attributes of the element or UI SDK part it draws: className, aria-label, events and the rest.
Without React
The same look on any HTML, with the classes th[aria-sort] > button.ui-sort.
With the CSS in parts (/ui/css/), it needs these, besides the ones every page loads:
components/table-sorting-chosen-rows.cssShowing things: states, do and don’t
A column heading that sorts the table; a chosen row is aria-selected="true".
States. Lists, tables and boards have three more states besides their content: empty (Empty, with the first action inside), loading (Skeleton) and failed (Alert tone="danger"). A chosen row shows in ink, never in the brand colour.
Do
- Put numbers, dates and codes in
ui-mono(in a table cell,ui-num, which also aligns them). - Let a
Tableturn into blocks on a phone; give itscrollonly when it is read down its columns. - Show a status in words and colour together (
Badge tone="success"with "Paid"), never colour alone.
Don't
- Don't put a card round a
Table,List,Cells,CalendarorEmpty: they draw their own box. - Don't truncate a name or a price to fit; let it wrap. Truncate only file names and addresses.
- Don't use the status colours (success, warning, danger, info) for anything but those meanings.