Prepared Docs

Prepared Docs

⌘K

    Loading navigation…

User

  1. Blocks
  2. Filters
  3. Sort Models Hooks

Sort Models and Hooks

Headless Sorting API

Import sort and group models and headless hooks from @prepared911/ui-filters.

SortCriterion

NameTypeDescription
idstringStable id suitable for persistence.
labelstringCriterion label.
iconSVGAssetOptional decorative icon.
fieldkeyof T & stringShorthand field comparison.
compare(a, b) => numberAscending comparator; wins over field.
fixedDirectionSortDirectionPins direction while selected. Leaving a pinned criterion resets an unpinned criterion to ascending.
disabledbooleanDisables the criterion.

GroupCriterion

NameTypeDescription
idstringStable id suitable for persistence.
labelstringGroup label.
iconSVGAssetOptional decorative icon.
getKey(item) => string | string[] | null | undefinedSupports multiple keys; nullish values remain ungrouped.
getLabel(key, items) => stringOptional bucket label.
compareGroups(a, b) => numberOptional group ordering.
disabledbooleanDisables the group.

Hooks

useSortState

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.

useSortedData

Embeds useSortState and returns memoized sortedData. Sorting is non-mutating through toSorted.

useGroupedData

Transforms { data, grouping, groupId } into { groups, ungrouped }.

Previous

Data Table / Accessibility

Next

Filters / Usage

On this page

SortCriterion
GroupCriterion
Hooks
useSortState
useSortedData
useGroupedData