Sort nodes with multi-key and null ordering
Sort orders by several keys in priority order with explicit null placement, so every backend produces the same row order.
Live example
Expected behavior
Each Shift+click appends a sort node and the header shows a priority badge. Changing the default nulls order rewrites the nulls value on existing nodes. Exceeding the maximum drops the oldest key and shows a notice.
Source
const api = createGrid({
rows, columns,
maxSortKeys: 3,
defaultNullsOrder: 'last',
});
api.setSort([
{ columnId: 'status', direction: 'asc' },
{ columnId: 'amount', direction: 'desc', nulls: 'last' },
]);
api.on('sortChange', ({ sort }) => console.log(sort)); // nulls is always explicit
api.setQueryAst({ ...api.getQueryAst(), sort: tooManyKeys }); // throws GridConfigErrorconst api = createGrid({
rows, columns,
maxSortKeys: 3,
defaultNullsOrder: 'last',
});
api.setSort([
{ columnId: 'status', direction: 'asc' },
{ columnId: 'amount', direction: 'desc', nulls: 'last' },
]);
api.on('sortChange', ({ sort }) => console.log(sort)); // nulls is always explicit
api.setQueryAst({ ...api.getQueryAst(), sort: tooManyKeys }); // throws GridConfigErrorconst api = createGrid({
rows, columns,
maxSortKeys: 3,
defaultNullsOrder: 'last',
});
api.setSort([
{ columnId: 'status', direction: 'asc' },
{ columnId: 'amount', direction: 'desc', nulls: 'last' },
]);
api.on('sortChange', ({ sort }) => console.log(sort)); // nulls is always explicit
api.setQueryAst({ ...api.getQueryAst(), sort: tooManyKeys }); // throws GridConfigErrorconst api = createGrid({
rows, columns,
maxSortKeys: 3,
defaultNullsOrder: 'last',
});
api.setSort([
{ columnId: 'status', direction: 'asc' },
{ columnId: 'amount', direction: 'desc', nulls: 'last' },
]);
api.on('sortChange', ({ sort }) => console.log(sort)); // nulls is always explicit
api.setQueryAst({ ...api.getQueryAst(), sort: tooManyKeys }); // throws GridConfigError// JavaScript interop module
const api = createGrid({
rows, columns,
maxSortKeys: 3,
defaultNullsOrder: 'last',
});
api.setSort([
{ columnId: 'status', direction: 'asc' },
{ columnId: 'amount', direction: 'desc', nulls: 'last' },
]);
api.on('sortChange', ({ sort }) => console.log(sort)); // nulls is always explicit
api.setQueryAst({ ...api.getQueryAst(), sort: tooManyKeys }); // throws GridConfigErrorAPI reference
| Kind | Name | Type | Description |
|---|---|---|---|
| Type | SortNode | — | A sort key with columnId, direction and explicit nulls. |
| Option | maxSortKeys | — | Maximum number of sort keys. Defaults to 3. |
| Option | defaultNullsOrder | — | first, last or backend-default for nodes without nulls. |
| Method | setSort | — | Applies an ordered list of sort nodes. |
| Event | sortChange | — | Fires once per change with the explicit sort nodes. |
Acceptance criteria
- Sort nodes preserve user-chosen priority order (met)
- The 'nulls' property is always explicit in the serialized AST, never omitted (met)
- A sort list longer than maxSortKeys fails validation when supplied via setQueryAst (met)
- Sorting the same field twice in one list is rejected as a duplicate (met)