Skip to content

defaultComparator

Default comparator used when no column-level sortComparator is configured. Pushes null/undefined to the end and compares remaining values via > / < operators, which works correctly for numbers and falls back to lexicographic comparison for strings.

Use this as a fallback inside a custom sortComparator when you only need special handling for certain values:

function defaultComparator(a: unknown, b: unknown): number
NameTypeDescription
aunknown
bunknown
import { defaultComparator } from '@toolbox-web/grid';
const column = {
field: 'priority',
sortComparator: (a, b, rowA, rowB) => {
// Pin "urgent" to the top, then fall back to default ordering
if (a === 'urgent') return -1;
if (b === 'urgent') return 1;
return defaultComparator(a, b);
},
};
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt