TanStack

constructSortFn

Function: constructSortFn()

ts
function constructSortFn<TFeatures, TData>(def): CreatedSortFn<TFeatures, TData>;

Defined in: features/row-sorting/sortFns.ts:38

Builds a SortFn from a value-level comparator plus an optional resolveDataValue normalizer.

The sort comparator receives both rows' data values, each already passed through resolveDataValue when one is defined. Keeping normalization in the resolver means a variant of an existing sorting function only has to swap the resolver, not re-implement the comparison.

The definition is attached to the returned function, so a variant can be created by spreading a built-in sorting function and overriding what differs:

ts
const stripDiacritics = (value: string) =>
  value.normalize('NFD').replace(/\p{Diacritic}/gu, '')

const alphanumericIgnoreDiacritics = constructSortFn({
  ...sortFn_alphanumeric,
  resolveDataValue: (value) =>
    stripDiacritics(sortFn_alphanumeric.resolveDataValue!(value)),
})

Type Parameters

TFeatures

TFeatures extends TableFeatures = any

TData

TData extends RowData = any

Parameters

def

SortFnDef<TFeatures, TData>

Returns

CreatedSortFn<TFeatures, TData>