# defaultComparator

> _Since v0.2.7_

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:

```ts
function defaultComparator(a: unknown, b: unknown): number
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `a` | <code>unknown</code> |  |
| `b` | <code>unknown</code> |  |

## Example

```typescript
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);
  },
};
```

## See Also

- [`BaseColumnConfig.sortComparator`](/grid/api/core/interfaces/basecolumnconfig.md#sortcomparator) for column-level comparators
- [`builtInSort`](/grid/api/core/functions/builtinsort.md) for the full sort handler that uses this comparator
