# comparator

Compares two values and rows for sorting. Negative, zero, and positive results mean before, equal, and after.

Canonical: https://grid.syidax.com/docs/columns/comparator/

<a id="meaning"></a>

## What does this API do?

Compares two values and rows for sorting. Negative, zero, and positive results mean before, equal, and after.

<a id="contract"></a>

## Exact input and result types

```typescript
comparator?: GridCallback<[TValue, TValue, Readonly<TData>, Readonly<TData>], number>
```

| Item | Value |
| --- | --- |
| Required | Optional |
| Input type | GridCallback<[TValue, TValue, Readonly<TData>, Readonly<TData>], number> |

<a id="usage"></a>

## Usage flow

Set this on an individual column object in columnDefs. Pass arrays, objects, and callbacks through JavaScript, and use new arrays or objects when applying changes.

<a id="types"></a>

## Read related types

- [GridCallback](https://grid.syidax.com/docs/types/GridCallback.md)

<a id="recipes"></a>

## Feature explanations and examples

- [Single and multiple sorting](https://grid.syidax.com/docs/features/sorting.md) — Sorting changes display order without modifying data values. Single sorting uses one criterion; multiple sorting uses prioritized criteria.
