Compiles a SortState into a comparator function for use with ISortableDatasource.sortBy().
The comparator performs locale-aware string comparison by default, treating all values as strings. Numeric and date comparisons are not supported — if you need custom comparison logic, pass a custom comparator directly to the datasource.
The sort state (key and direction), or null/undefined for no sorting.
A comparator function (a, b) => number, or null if state is null/undefined.
(a, b) => number
null
import { toComparator } from '@theredhead/lucid-kit';import { SortableArrayDatasource } from '@theredhead/lucid-foundation';const ds = new SortableArrayDatasource(items);const state = { key: 'name', direction: 'asc' };ds.applyComparator(toComparator(state)); Copy
import { toComparator } from '@theredhead/lucid-kit';import { SortableArrayDatasource } from '@theredhead/lucid-foundation';const ds = new SortableArrayDatasource(items);const state = { key: 'name', direction: 'asc' };ds.applyComparator(toComparator(state));
Compiles a SortState into a comparator function for use with ISortableDatasource.sortBy().
The comparator performs locale-aware string comparison by default, treating all values as strings. Numeric and date comparisons are not supported — if you need custom comparison logic, pass a custom comparator directly to the datasource.