Skip to content

multiSort ​

A plain click sorts by one column, as always. Shift+click (Shift+Enter on the focused header) adds that column as the next sort key; doing it again flips its direction, a third time removes it. The rank of every key shows in its header.

Usage ​

js
import { Datagrid, arraySource, multiSort } from "@akinozgen17/datagrids";

const grid = new Datagrid("#agents", {
  label: "Agents",
  columns,
  sort: [["unit", "asc"]],
  use: [arraySource(rows), multiSort({ max: 3 })],
});

grid.sort([["unit", "asc"], ["amount", "desc"]]); // the same from code
grid.multiSort.toggle("date"); // like a Shift+click

Options ​

OptionTypeDefaultDescription
maxnumber3Most keys at once; adding one more drops the oldest.
messagesPartial<MultiSortMessages>localehint (header tooltip), rank(n, dir) (screen-reader text), announce(cols).
canbooleantruePermission flag: false attaches nothing.

API added to the grid ​

grid.multiSort.toggle(key) adds, flips or removes a key exactly like a Shift+click.

Wire ​

The classic wire (and yajra) carries every key as order[0..n], dgp as sort: [{ key, dir }, …] (sort=-date,name with GET). Client mode sorts by all keys in order.

The Laravel paginator sends only the first key (sort=-date); the other keys show in the headers but don't reach the server.

Accessibility ​

aria-sort stays on the primary column only (ARIA allows one). Secondary keys show their rank and direction visually and in the sort button's accessible name ("…, sort key 2, descending"); every change is announced in the grid's live region.

Released under the MIT License.