Home/Rows/Row Sorting
Rows

Row Sorting

Click any sortable column header to sort. Click again to reverse. Hold Shift and click multiple headers to enable multi-column sort.

Enabling sorting

Sorting is opt-in per column. This grid opens unsorted — click a header once for ascending, again for descending, a third time to clear it.

#
First Name
Last Name
Department
Salary ($)
Status
1
Alice
Smith
Engineering
40000
Inactive
2
Bob
Smith
Marketing
41000
Active
3
Carol
Smith
Sales
42000
Active
4
David
Smith
HR
43000
Active
5
Emma
Smith
Finance
44000
Active
6
Frank
Smith
Operations
45000
Active
7
Grace
Smith
Design
46000
Active
8
Henry
Smith
Legal
47000
Inactive
9
Iris
Smith
Product
48000
Active
10
Jack
Smith
Support
49000
Active
11
Kate
Smith
Engineering
50000
Active
12
Liam
Smith
Marketing
51000
Active
13
Mia
Smith
Sales
52000
Active
14
Noah
Smith
HR
53000
Active
15
Olivia
Smith
Finance
54000
Inactive
16
Paul
Smith
Operations
55000
Active
17
Quinn
Smith
Design
56000
Active
18
Rachel
Smith
Legal
57000
Active
19
Sam
Smith
Product
58000
Active
20
Tara
Smith
Support
59000
Active
20 rows loaded​
20 / 500 records

Sorting is opt-in per column: set sortable: true on any column to show a sort icon in its header and make it clickable. Each click cycles ascending → descending → unsorted.

{ key: 'salary', name: 'Salary ($)', prop: 'salary', sortable: true }

A column without it is inert — no icon, no cursor change, and a click does nothing. That is the usual reason a header "looks sortable but isn't": the grid-level option is on and the column flag is missing.

Initial sorts

The same grid, opened already sorted by salary, highest first. The sort rides the very first fetch — the server never sends an unsorted page that the reader then watches reorder.

#
First Name
Last Name
Department
Salary ($)
Status
80
Bob
Brown
Support
119000
Active
160
David
Miller
Support
119000
Active
240
Frank
Moore
Support
119000
Active
320
Henry
Thomas
Support
119000
Active
400
Jack
Harris
Support
119000
Inactive
480
Liam
Lee
Support
119000
Active
79
Alice
Brown
Product
118000
Active
159
Carol
Miller
Product
118000
Active
239
Emma
Moore
Product
118000
Inactive
319
Grace
Thomas
Product
118000
Active
399
Iris
Harris
Product
118000
Active
479
Kate
Lee
Product
118000
Active
78
Zane
Williams
Legal
117000
Inactive
158
Bob
Miller
Legal
117000
Active
238
David
Moore
Legal
117000
Active
318
Frank
Thomas
Legal
117000
Active
398
Henry
Harris
Legal
117000
Active
478
Jack
Lee
Legal
117000
Active
77
Yara
Williams
Design
116000
Active
157
Alice
Miller
Design
116000
Active
20 rows loaded​
20 / 500 records

config.initialSorts pre-sorts the grid on first load, without waiting for a click.

initialSorts: [{ key: 'salary', dir: 'desc' }]

It is included in the params of the first fetchRows() call, so the server returns the first page already in order. Nothing arrives unsorted and then rearranges under the reader.

Multi-column sort

Sorted by department, with salary ordering the rows inside each one — two sorts active at once. Hold Shift and click a third header to add to it; click one without Shift to drop back to a single sort.

#
First Name
Last Name
Departmentsort priority 1
Salary ($)sort priority 2
Status
77
Yara
Williams
Design
116000
Active
157
Alice
Miller
Design
116000
Active
237
Carol
Moore
Design
116000
Active
317
Emma
Thomas
Design
116000
Active
397
Grace
Harris
Design
116000
Active
477
Iris
Lee
Design
116000
Inactive
67
Olivia
Williams
Design
106000
Active
147
Quinn
Garcia
Design
106000
Active
227
Sam
Wilson
Design
106000
Active
307
Uma
Anderson
Design
106000
Active
387
Wendy
White
Design
106000
Active
467
Yara
Lewis
Design
106000
Active
57
Emma
Williams
Design
96000
Inactive
137
Grace
Garcia
Design
96000
Active
217
Iris
Wilson
Design
96000
Active
297
Kate
Anderson
Design
96000
Active
377
Mia
White
Design
96000
Active
457
Olivia
Lewis
Design
96000
Active
47
Uma
Johnson
Design
86000
Active
127
Wendy
Jones
Design
86000
Inactive
20 rows loaded​
20 / 500 records

A plain click sorts by that column alone and clears any other active sort. Hold Shift (or Ctrl/Cmd) and click to add a column instead. On the keyboard, Shift+Enter on a focused header does the same. Every sorted column keeps its own direction chevron, and once two or more are active each one also shows a small number: 1 is the primary sort, 2 breaks its ties, and so on.

An added column joins at the bottom of that list, so the first column you click keeps deciding the order and each extra click refines it — you build "by department, then by salary within it" in the order you would say it. Click a header without Shift at any point to drop back to sorting by that column alone.

Set the same thing in config with priority — 0 is the primary sort. The grid below is ordered by department, with salary ordering the rows inside each one:

multiSortMode: 'modifier',   // plain click = single, Shift/Ctrl+click = add
initialSorts: [
  { key: 'department', dir: 'asc',  priority: 0 },   // primary
  { key: 'salary',     dir: 'desc', priority: 1 },   // tie-break inside each department
]

Reading older code? priority is optional, and when no entry has it the order comes from the array instead — with the last entry as the primary sort, the opposite of SQL's ORDER BY. A header Shift+click does not follow that reading: it always adds the column at the lowest priority, so the column you sorted first stays primary. Both readings work and neither is going away; priority is simply the one that cannot be misread — including by your server, which receives it on every request.

Try it here and the two-column sort above disappears on your first plain click — that is this mode doing exactly what it promises. The next example is the same grid with the other setting, where no key is needed.

Multi-column sort without a modifier

The same grid with multiSortMode set to click. Click Department, then Salary, then Status — every click adds instead of replacing, so no key is held down.

#
First Name
Last Name
Department
Salary ($)
Status
1
Alice
Smith
Engineering
40000
Inactive
2
Bob
Smith
Marketing
41000
Active
3
Carol
Smith
Sales
42000
Active
4
David
Smith
HR
43000
Active
5
Emma
Smith
Finance
44000
Active
6
Frank
Smith
Operations
45000
Active
7
Grace
Smith
Design
46000
Active
8
Henry
Smith
Legal
47000
Inactive
9
Iris
Smith
Product
48000
Active
10
Jack
Smith
Support
49000
Active
11
Kate
Smith
Engineering
50000
Active
12
Liam
Smith
Marketing
51000
Active
13
Mia
Smith
Sales
52000
Active
14
Noah
Smith
HR
53000
Active
15
Olivia
Smith
Finance
54000
Inactive
16
Paul
Smith
Operations
55000
Active
17
Quinn
Smith
Design
56000
Active
18
Rachel
Smith
Legal
57000
Active
19
Sam
Smith
Product
58000
Active
20
Tara
Smith
Support
59000
Active
20 rows loaded​
20 / 500 records

multiSortMode: 'click' drops the modifier: every plain click adds a column to the sort instead of replacing it. Click Department, then Salary, then Status, and all three stay on.

multiSortMode: 'click'

The trade is the other direction: getting back to a single column now takes clicking the others until each cycles through descending and off. Pick this when your readers sort by several columns most of the time; keep the default when a single sort is the common case.

Server vs client mode

The same columns with sortMode set to client. Sorting here reorders the rows already in the browser — no request goes out, and the header responds instantly.

#
First Name
Last Name
Department
Salary ($)
Status
80
Bob
Brown
Support
119000
Active
79
Alice
Brown
Product
118000
Active
78
Zane
Williams
Legal
117000
Inactive
77
Yara
Williams
Design
116000
Active
76
Xander
Williams
Operations
115000
Active
75
Wendy
Williams
Finance
114000
Active
74
Victor
Williams
HR
113000
Active
73
Uma
Williams
Sales
112000
Active
72
Tara
Williams
Marketing
111000
Active
71
Sam
Williams
Engineering
110000
Inactive
70
Rachel
Williams
Support
109000
Active
69
Quinn
Williams
Product
108000
Active
68
Paul
Williams
Legal
107000
Active
67
Olivia
Williams
Design
106000
Active
66
Noah
Williams
Operations
105000
Active
65
Mia
Williams
Finance
104000
Active
64
Liam
Williams
HR
103000
Inactive
63
Kate
Williams
Sales
102000
Active
62
Jack
Williams
Marketing
101000
Active
61
Iris
Williams
Engineering
100000
Active
60
Henry
Williams
Support
99000
Active
59
Grace
Williams
Product
98000
Active
58
Frank
Williams
Legal
97000
Active
57
Emma
Williams
Design
96000
Inactive
56
David
Williams
Operations
95000
Active
100 / 500 records

sortMode decides where the work happens, and it is the one sorting option that changes what your server sees.

  • 'server' (default) — a sort click resets the grid and calls fetchRows() with the new sorts array. Your data source applies it. The other three examples on this page are in this mode.
  • 'client' — the grid reorders the rows it already holds. No fetchRows() call is made on a sort change, and it passes sorts: [] so the server never double-sorts. Dot-notation prop paths, valueGetter and a custom comparator all work here.

Client mode sorts the rows in the browser, not the dataset. This example loads 100 rows at a time so that distinction is visible; with a small page you would be reordering a fraction of the data while the header implies otherwise.

(sortChange) output

The (sortChange) output emits the full SortConfig[] array after every sort update. Use it to sync sort state to a URL query parameter, send analytics events, or update a "saved view" indicator.

Mouse & keyboard

InteractionEffect
Click headerCycle ascending → descending → unsorted
Shift + click headerAdd the column to a multi-column sort
Click a sorted header againReverse its direction. Without Shift this also clears the other sorts; with it, the column moves to the lowest priority

In sortMode: 'server' every sort click resets the loaded rows and refetches from offset 0. For large page sizes or slow endpoints, prefer 'client' mode when the full dataset is already in memory — no network round-trip per click.

Sorting options

PropertyTypeDefaultDescription
column.sortablebooleanfalseOpt a column into sorting — shows the header sort icon and makes it clickable.
config.sortMode'server' | 'client''server'server refetches with params.sorts; client sorts loaded rows in memory with no fetch.
config.multiSortMode'modifier' | 'click''modifier'modifier: plain click = single sort, Shift/Ctrl+click adds. click: every plain click accumulates (legacy).
config.initialSortsSortConfig[][]Pre-sort on first load — included in the first fetchRows() call.
SortConfig.prioritynumber—Which sort wins: 0 is the primary sort, 1 the first tie-break. Omit it on every entry and the array order decides instead, with the last entry as primary.
column.comparator(a, b, rowA, rowB) => number—Custom compare function for client-mode sorting.
column.valueGetter(row) => unknown—Derives the sort value in client mode (also used for display and export).
(sortChange)SortConfig[]—Output — emits the full sort state after every change.