View as Markdown

Grouping

Grouping

Group rows by one or more columns from the drop area, the keyboard or methods; virtualized, with preserved expansion.

Grouping is a core pipeline stage. Rows group by any number of columns; each level sorts ascending or descending and grouped columns always sort before the user sort. A column can opt out of grouping. A number or date column with groupByFormat groups by its formatted value, for example by month.

A column's groupKey(row) groups by a custom key instead of the cell value: rows with an equal key (dates by time) form one group, so a key can bucket numbers into bands or combine fields. Groups order by key in the column's group direction: blanks first, then booleans, numbers and dates by value, then strings by the locale collator. The key is the group's key in captions, events, expansion paths and toggleGroup. With groupKey, groupByFormat no longer decides the buckets: it only formats the caption with the column formatter (the demo shows "$250" for the 250 band); otherwise the caption is the key as text. groupKey runs once per row on every regroup and only on local data; lazy (server) grouping groups by the field.

<DataGrid
  data={orders}
  columns={[
    { field: 'country', header: 'Country' },
    { field: 'orderDate', header: 'Month', type: 'date', format: 'yMMM', groupByFormat: true },
    { field: 'amount', header: 'Amount', type: 'number', groupKey: (row) => Math.floor(row.amount / 250) * 250 },
    { field: 'note', header: 'Note', groupable: false },
  ]}
  sorting
  grouping={{ groupBy: ['country'], reorderable: true, showGroupedColumns: true }}
  onGroupChange={(event) => console.log(event.action, event.groupBy)}
/>

grouping.groupBy lists the grouped fields in order; it is reactive and part of the server render, so a grid renders already grouped.

Drop area and chips

The drop area above the header can be hidden with grouping.showDropArea: false. Dragging a header into it groups by that column. Each grouped column is a chip that can be reordered by drag or Alt+Arrow, flipped between ascending and descending, and removed. Reordering is opt in (grouping.reorderable); the direction toggle follows sorting (shown when the grid sorts and the column is sortable); grouping.showRemoveButton (default true) shows the remove button. grouping.showHeaderToggle (opt in) adds a group toggle button to the header of every groupable column that groups or ungroups by it. Grouped columns are hidden by default, and grouping.showGroupedColumns keeps them visible. On a focused chip, Delete or Backspace removes it.

Captions and expansion

Each group shows a caption row with the column, the key and the item count, an indent per level and a toggle button that exposes aria-expanded. The caption cell, which takes focus, carries aria-expanded too and describes the level and item count ("Level 2, 15 items", localeText.groupLevel); the grid stays a grid, so rows carry no aria-level. The drop area renders above the grid element, outside it. grouping.renderCaption(ctx) replaces the caption text and receives the field, key, formattedKey, count, aggregates, expanded and toggle. Groups start expanded (grouping.defaultExpanded, default true) and onBeforeGroupToggle / onGroupToggle control expansion; api.expandAllGroups(), api.collapseAllGroups() and api.toggleGroup(target, expanded?) (by row id, path key or path) expand or collapse all groups or one. On a focused caption, Enter toggles the group and ArrowLeft / ArrowRight collapse or expand it. Expansion is keyed by the group path, so it survives virtual scrolling, sorting and data refreshes.

Methods, events and keyboard

api.groupColumn(field, index?), api.ungroupColumn(field) and api.clearGrouping() group, ungroup and clear. onBeforeGroupChange (cancel with preventDefault()) fires before every grouping change with the action ('group', 'ungroup', 'move' or 'clear'), the field and the proposed groupBy, and onGroupChange after it. Ctrl+Space on a focused header groups or ungroups it; Ctrl/⌘+ArrowUp and Ctrl/⌘+ArrowDown in the body collapse or expand all groups.

Grouping

Open demo

Multi-level grouping over 5,000 virtualized rows with the drop area, chips, group-by-format, a custom group key, caption templates, collapse state, cancelable changes, group methods and events.

Order
Country
City
Category
Priority
Placed
Month
Amount
Amount band
Country: France — 1077 orders
Category: Tea — 305 orders
ORD-10045
France
Lyon
Tea
Normal
Sep 17, 2026
Sep 2026
$32.51
$33
ORD-10067
France
Reims
Tea
High
Aug 15, 2026
Aug 2026
$55.04
$55
ORD-10075
France
Reims
Tea
Normal
Jul 27, 2026
Jul 2026
$26.36
$26
ORD-10091
France
Reims
Tea
Normal
Aug 18, 2026
Aug 2026
$96.90
$97
ORD-10102
France
Lyon
Tea
Normal
Feb 22, 2026
Feb 2026
$97.54
$98
ORD-10126
France
Lyon
Tea
High
Jun 3, 2026
Jun 2026
$55.04
$55
ORD-10150
France
Lyon
Tea
Normal
Dec 13, 2026
Dec 2026
$33.30
$33
ORD-10166
France
Reims
Tea
Normal
Mar 5, 2026
Mar 2026
$63.75
$64
ORD-10193
France
Reims
Tea
Normal
Mar 5, 2026
Mar 2026
$38.25
$38
ORD-10224
France
Lyon
Tea
Normal
Nov 26, 2026
Nov 2026
$96.66
$97
ORD-10229
France
Reims
Tea
Low
Jan 10, 2026
Jan 2026
$34.43
$34
ORD-10238
France
Reims
Tea
Low
Jun 21, 2026
Jun 2026
$109.01
$109
ORD-10239
France
Lyon
Tea
Normal
Dec 18, 2026
Dec 2026
$114.75
$115
ORD-10250
France
Lyon
Tea
High
May 23, 2026
May 2026
$54.19
$54
ORD-10267
France
Reims
Tea
High
Jun 1, 2026
Jun 2026
$133.24
$133
ORD-10274
France
Lyon
Tea
Normal
Mar 5, 2026
Mar 2026
$66.60
$67
ORD-10278
France
Reims
Tea
Low
Jun 27, 2026
Jun 2026
$17.58
$18
ORD-10309
France
Reims
Tea
Normal
Dec 8, 2026
Dec 2026
$27.75
$28

Drag a header into the drop area to group; drag chips to reorder; click a chip to flip its direction. Keyboard: Ctrl+Space on a header groups it, Ctrl+Up / Ctrl+Down collapse or expand all, Alt+Arrow moves a focused chip.

No events yet.

Grouping with column virtualization

Grouping works with row and column virtualization on. Only the visible columns of the center zone render; the group indent is frozen at the start edge like a pinned column, and caption text stays in view while the grid scrolls sideways. Captions span the full row width, so they never depend on which columns are rendered.

Grouping with column virtualization

Open demo

20,000 rows by 80 columns grouped by two levels with row and column virtualization on; the group indent and captions stay at the start edge while scrolling sideways.

#
Value 1
Value 2
Text 3
Value 4
Value 5
Text 6
Value 7
Value 8
Text 9
Value 10
Value 11
Text 12
Value 13
Value 14
Text 15
Value 16
Value 17
Text 18
Value 19
Value 20
Region: East - 5,000 items
Team: Atlas - 1,667 items
1
19,690
76,900
golf-1
63,257
93,463
charlie-1
73,180
76,755
delta-1
66,097
4,541
bravo-1
17,543
8,514
echo-1
35,140
25,990
juliet-1
39,531
65,365
13
11,378
92,348
juliet-13
50,530
91,535
foxtrot-13
46,779
58,126
hotel-13
74,472
75,706
delta-13
20,782
93,092
foxtrot-13
59,582
68,970
charlie-13
24,546
31,363
25
86,555
38,642
hotel-25
5,115
37,662
charlie-25
13,437
61,537
charlie-25
51,405
42,370
charlie-25
88,784
19,458
foxtrot-25
77,357
80,987
juliet-25
92,680
26,923
37
39,389
47,899
charlie-37
12,089
69,188
golf-37
17,284
39,820
india-37
25,311
28,197
echo-37
85,409
93,355
india-37
4,232
77,288
hotel-37
11,050
73,004
49
30,557
42,247
india-49
93,337
63,661
echo-49
86,766
78,915
charlie-49
81,091
79,474
bravo-49
98,118
17,578
bravo-49
31,644
95,841
golf-49
25,342
53,123
61
99,078
55,376
bravo-61
88,100
90,848
foxtrot-61
33,448
96,514
foxtrot-61
19,699
94,874
bravo-61
83,900
12,282
delta-61
37,262
6,149
india-61
18,529
61,163
73
22,253
63,233
golf-73
17,465
25,766
hotel-73
45,843
82,710
hotel-73
16,210
92,157
hotel-73
838
15,334
bravo-73
7,643
11,961
charlie-73
32,232
9,989
85
15,657
70,150
alpha-85
25,333
6,880
foxtrot-85
20,494
4,739
golf-85
87,610
97,906
delta-85
67,283
36,890
foxtrot-85
55,112
7,088
delta-85
17,793
97,498
97
30,556
47,183
foxtrot-0
19,357
37,473
charlie-0
16,941
69,592
foxtrot-0
61,605
97,705
foxtrot-0
59,778
37,539
juliet-0
27,950
20,533
echo-0
99,739
86,744
109
91,077
20,004
charlie-12
38,391
77,748
charlie-12
29,879
6,398
juliet-12
64,329
48,025
delta-12
8,807
7,178
juliet-12
90,284
57,807
foxtrot-12
2,971
22,378
121
1,969
21,809
india-24
47,864
9,487
alpha-24
97,594
97,899
golf-24
51,271
90,522
golf-24
87,517
42,741
india-24
25,396
92,061
bravo-24
20,772
79,378
133
70,959
7,890
foxtrot-36
14,182
37,846
alpha-36
6,002
31,592
bravo-36
99,664
17,446
delta-36
82,760
98,793
bravo-36
45,518
27,653
delta-36
22,421
46
145
88,085
19,818
hotel-48
50,815
96,126
charlie-48
49,715
99,493
delta-48
41,372
29,550
golf-48
74,580
42,423
foxtrot-48
10,223
29,984
golf-48
24,959
63,926
157
28,682
73,908
bravo-60
31,273
9,550
alpha-60
57,900
88,079
juliet-60
4,274
32,789
alpha-60
14,235
63,928
juliet-60
52,042
84,573
bravo-60
93,806
22,477
169
59,850
34,406
india-72
30,316
17,807
delta-72
31,074
56,575
foxtrot-72
54,630
44,413
foxtrot-72
48,628
39,179
india-72
74,160
85,665
alpha-72
7,408
39,237
181
58,450
13,927
juliet-84
69,397
98,611
hotel-84
98,784
5,581
charlie-84
3,106
39,202
golf-84
45,356
87,903
juliet-84
44,559
85,902
hotel-84
54,183
99,913
193
49,111
34,522
charlie-96
76,132
95,038
india-96
6,857
54,516
juliet-96
54,167
89,791
delta-96
1,309
28,666
golf-96
24,226
62,754
india-96
29,050
25,192
205
74,019
22,427
alpha-11
75,886
60,686
hotel-11
39,660
54,593
india-11
52,482
85,696
foxtrot-11
5,051
24,644
bravo-11
24,678
8,911
charlie-11
12,541
92,768

Scroll sideways: the group indent, the captions and the pinned # column stay in place while only the visible columns render.