Skip to content
API/toggleSort

toggleSort

src/utils/toggle-sort.tsfunction
toggleSort(sorts: readonly Sort[], field: string, options: ToggleSortOptions): readonly Sort[]

The sorts after a click on a column header.

By default the field becomes the only sort. It flips only when it is the primary sort — the first one, the one getAriaSort() announces — and starts ascending otherwise, even if a secondary sort already names it. With multiple the other sorts are kept: the field flips in place wherever it is, or is appended ascending. The input is left untouched.

Parameter Type Description
sorts readonly Sort[] The current sorts
field string The API field clicked
options ToggleSortOptions Whether to keep the other sorts

Returns — The new sorts