Headless Sorting API
Import sort and group models and headless hooks from @prepared911/ui-filters.
| Name | Type | Description |
|---|---|---|
id | string | Stable id suitable for persistence. |
label | string | Criterion label. |
icon | SVGAsset | Optional decorative icon. |
field | keyof T & string | Shorthand field comparison. |
compare | (a, b) => number | Ascending comparator; wins over field. |
fixedDirection | SortDirection | Pins direction while selected. Leaving a pinned criterion resets an unpinned criterion to ascending. |
disabled | boolean | Disables the criterion. |
| Name | Type | Description |
|---|---|---|
id | string | Stable id suitable for persistence. |
label | string | Group label. |
icon | SVGAsset | Optional decorative icon. |
getKey | (item) => string | string[] | null | undefined | Supports multiple keys; nullish values remain ungrouped. |
getLabel | (key, items) => string | Optional bucket label. |
compareGroups | (a, b) => number | Optional group ordering. |
disabled | boolean | Disables the group. |
Controlled or uncontrolled sort and group selection. It exposes setCriterion, toggleCriterion, setDirection, toggleDirection, setGroup, and toggleGroup.
A criterion's fixedDirection applies only while that criterion is selected. Switching or clearing a pinned criterion resets direction to ascending before an unpinned criterion is selected. Controlled consumers receive the normalized direction through onChange.
Embeds useSortState and returns memoized sortedData. Sorting is non-mutating through toSorted.
Transforms { data, grouping, groupId } into { groups, ungrouped }.