@jsvision/ui / sortRows
Function: sortRows()
sortRows<
T>(rows,columns,sort):T[]
Defined in: ui/src/table/columns.ts:248
Produce a new display ordering of rows by column + direction. Stable (ties keep source order), and the original rows array is never mutated.
Type Parameters
T
T
Parameters
rows
T[]
The source rows.
columns
Column<T>[]
The column descriptors (supply the comparator / accessor).
sort
The active sort, or null for source order.
Returns
T[]
A new sorted array, or the original rows unchanged when sort is null or its column index is out of range.
Example
ts
import { sortRows } from '@jsvision/ui';
import type { Column } from '@jsvision/ui';
interface Row {
qty: number;
}
const cols: Column<Row>[] = [
{ title: 'Qty', accessor: (r) => String(r.qty), width: 'auto' as const, compare: (a, b) => a.qty - b.qty },
];
sortRows([{ qty: 1000 }, { qty: 9 }], cols, { col: 0, dir: 'asc' }); // [{ qty: 9 }, { qty: 1000 }]