Column Sorting

Let users sort columns ascending or descending — or drive sort from your server.

Enable sorting

Set sortable: true on a column. Users click the header to cycle sort. Nested accessors like albums[0].title work too.

TypeScript
{
accessor: "name",
label: "Full Name",
width: "1fr",
sortable: true,
}

Custom sort cycle

Use sortingOrder to change the click cycle. Default is ["asc", "desc", null]. Prefer desc-first for numbers and dates.

TypeScript
{
accessor: "revenue",
label: "Revenue",
width: 120,
type: "number",
sortable: true,
sortingOrder: ["desc", "asc", null],
}

Initial sort

Set initialSortColumn and initialSortDirection so the table loads already sorted.

React TSX
<SimpleTable columns={columns} rows={rows} height="400px" initialSortColumn="revenue" initialSortDirection="desc" />

Custom comparator

Use comparator when you need multi-field or domain-specific sort logic with both rows.

TypeScript
{
accessor: "priority",
label: "Priority",
sortable: true,
comparator: ({ rowA, rowB, direction }) => {
if (rowA.priority !== rowB.priority) {
return direction === "asc"
? Number(rowA.priority) - Number(rowB.priority)
: Number(rowB.priority) - Number(rowA.priority);
}
return Number(rowB.score) - Number(rowA.score);
},
}

Sort with valueGetter

Use valueGetter when the sort value is nested or computed (instead of the raw accessor field).

TypeScript
{
accessor: "seniority",
label: "Seniority",
sortable: true,
valueGetter: ({ row }) => row.metadata?.seniorityLevel ?? 0,
}

External / server sorting

Set externalSortHandling and handle onSortChange — the table keeps sort UI while you supply pre-sorted rows.

React TSX
<SimpleTable
externalSortHandling
columns={columns}
rows={sortedRows}
onSortChange={(sort) => {
// fetch or sort sortedRows from sort.key / sort.direction
}}
/>

Example

External sorting example

Sort is handled outside the table; header indicators still update.

External Sort Status: No sorting applied

Props

Column Sorting Configuration

PropertyRequiredDescriptionExample
ColumnDef.sortable
boolean
Optional
Enables header click sorting for the column.
ColumnDef.sortingOrder
Array<'asc' | 'desc' | null>
Optional
Sort state cycle on header click. Default: ['asc', 'desc', null]. Omit null to keep a sort always on.
Optional
Custom compare using both rows and direction.
Optional
Extract or compute the value used for sorting (and often display).
initialSortColumn
string
Optional
Accessor to sort by on first load.
initialSortDirection
"asc" | "desc"
Optional
Direction for the initial sort. Defaults to 'asc'.
Optional
Fires when sort config changes (or null when cleared).
externalSortHandling
boolean
Optional
Disables internal sorting. Provide already-sorted rows (e.g. from your API).