Angular UI Components Documentation
This tutorial groups sales by category, region or product, writes a custom header for each group, and shows totals: built-in aggregates such as sum and average and a custom one, for each group and for the whole table.

Use an Angular CLI app set up as in Angular CLI with jQWidgets.
groupable turns grouping on and groups lists the columns to group by when the grid starts. showgroupsheader adds a bar above the headers: drag a column header there to group by it, or click the × on a group to remove it. The groups start collapsed; the arrow at the start of a group's row opens it.
<jqxGrid #grid
[theme]="'fluent'"
[width]="'100%'"
[height]="480"
[source]="source"
[columns]="columns"
[groupable]="true"
[groups]="initialGroups"
[groupsrenderer]="groupsrenderer"
[showgroupsheader]="true"
[showaggregates]="true"
[showgroupaggregates]="true"
[showstatusbar]="true"
[statusbarheight]="70">
</jqxGrid>
[groups] is bound to a field that never changes, like the other inputs (see Sorting, filtering and paging). To group by something else later, the component calls the grid's methods (step 3).
groupsrenderer writes each group's header. It receives the group's value and an object with its rows (subItems) and, when grouped by more than one column, its subgroups. When the grid also shows totals for each group, those total rows are in subItems too, marked totalsrow, so the count leaves them out:
export class App {
// …
// A group's header: its value and how many rows it holds. The typings declare data as a
// plain object; it holds the group's rows (subItems, with the group's totals rows marked
// totalsrow when showgroupaggregates is on) and, when grouped by more than one column,
// its subgroups.
readonly groupsrenderer = (_text?: string, group?: unknown, _expanded?: boolean, data?: object): string => {
const { subItems = [], subGroups = [] } = data as { subItems?: { totalsrow?: boolean }[]; subGroups?: unknown[] };
const rows = subItems.filter((row) => !row.totalsrow).length;
return `<div style="padding: 6px 4px;"><strong>${group}</strong> (${subGroups.length ? `${subGroups.length} groups` : `${rows} sales`})</div>`;
};
// …
}
A column's aggregates lists what to compute: sum, avg, min, max and count, or a custom aggregate, an object whose key is its label and whose function is called for each row with the running result and the row's value. showaggregates with showstatusbar shows them for the whole table, in the status bar under the rows, and showgroupaggregates adds a totals row at the end of each group.
export class App {
// …
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Region', datafield: 'region', width: 110 },
{ text: 'Category', datafield: 'category', width: 140 },
{ text: 'Product', datafield: 'product', width: 160 },
{
text: 'Units', datafield: 'units', width: 150, cellsalign: 'right', align: 'right',
// A custom aggregate next to the built-in ones: how many sales were of 30 units or more.
aggregates: [
'sum',
'avg',
{ 'Large sales': (count: number, value: number) => (value >= 30 ? count + 1 : count) }
]
},
{
text: 'Revenue', datafield: 'revenue', cellsalign: 'right', align: 'right', cellsformat: 'c0',
aggregates: ['sum', 'max'],
// How the totals are written. The grid passes them already formatted with the
// column's cellsformat ("$57,320").
aggregatesrenderer: (aggregates: Record<string, string>) =>
`<div style="padding: 6px; text-align: right;">Total ${aggregates['sum']}<br>Largest sale ${aggregates['max']}</div>`
}
];
// …
}
aggregatesrenderer writes the column's totals in the status bar. The values it receives are already formatted with the column's cellsformat, so the revenue total arrives as $57,320. The Units column has no renderer and no cellsformat, and the grid writes its totals as Sum:2940, Avg:24.5 and Large sales:45. The totals rows of the groups do not use aggregatesrenderer: their cells show the same name:value text, such as Sum:$18,140.
A select of the component's own groups by another column: cleargroups removes the grouping and addgroup adds a column to it. expandallgroups and collapseallgroups open and close every group.
export class App {
// …
// Grouping from the app's own control (the grid's header also takes drag and drop).
groupBy(field: string): void {
this.groupedBy.set(field);
const grid = this.grid();
grid.cleargroups();
if (field) {
grid.addgroup(field);
}
}
}
<p>
<label>
Group by
<select #groupField [value]="groupedBy()" (change)="groupBy(groupField.value)">
<option value="">Nothing</option>
<option value="category">Category</option>
<option value="region">Region</option>
<option value="product">Product</option>
</select>
</label>
<button type="button" (click)="grid.expandallgroups()">Expand all</button>
<button type="button" (click)="grid.collapseallgroups()">Collapse all</button>
</p>
In the template, #grid names the grid component itself, so the buttons call grid.expandallgroups() directly. The name hides the component's grid signal query there: grid() in this template would not compile.
src/app/app.ts:
import { Component, signal, viewChild } from '@angular/core';
import { jqxGridComponent, jqxGridModule } from 'jqwidgets-ng/jqxgrid';
interface Sale {
id: number;
region: string;
category: string;
product: string;
units: number;
revenue: number;
}
const regions = ['North', 'South', 'East', 'West'];
const catalog = [
{ category: 'Beverages', product: 'Chai', price: 18 },
{ category: 'Beverages', product: 'Chang', price: 19 },
{ category: 'Condiments', product: 'Aniseed Syrup', price: 10 },
{ category: 'Seafood', product: 'Ikura', price: 31 },
{ category: 'Seafood', product: 'Konbu', price: 6 },
{ category: 'Dairy', product: 'Mascarpone', price: 32 }
];
const sales: Sale[] = Array.from({ length: 120 }, (_, i) => {
const item = catalog[(i * 7) % catalog.length];
const units = 5 + ((i * 13) % 40);
return {
id: i + 1,
region: regions[(i * 3) % regions.length],
category: item.category,
product: item.product,
units,
revenue: units * item.price
};
});
@Component({ selector: 'app-root', imports: [jqxGridModule], templateUrl: './app.html' })
export class App {
readonly grid = viewChild.required<jqxGridComponent>('grid');
readonly groupedBy = signal('category');
// The grouping the grid starts with. A constant: changing the grouping later goes
// through the grid's methods, not through this input.
readonly initialGroups = ['category'];
readonly source = new jqx.dataAdapter({
localdata: sales,
datatype: 'array',
id: 'id',
datafields: [
{ name: 'region', type: 'string' },
{ name: 'category', type: 'string' },
{ name: 'product', type: 'string' },
{ name: 'units', type: 'number' },
{ name: 'revenue', type: 'number' }
]
});
readonly columns: jqwidgets.GridColumn[] = [
{ text: 'Region', datafield: 'region', width: 110 },
{ text: 'Category', datafield: 'category', width: 140 },
{ text: 'Product', datafield: 'product', width: 160 },
{
text: 'Units',
datafield: 'units',
width: 150,
cellsalign: 'right',
align: 'right',
// A custom aggregate next to the built-in ones: how many sales were of 30 units or more.
aggregates: [
'sum',
'avg',
{
'Large sales': (count: number, value: number) =>
value >= 30 ? count + 1 : count
}
]
},
{
text: 'Revenue',
datafield: 'revenue',
cellsalign: 'right',
align: 'right',
cellsformat: 'c0',
aggregates: ['sum', 'max'],
// How the totals are written. The grid passes them already formatted with the
// column's cellsformat ("$57,320").
aggregatesrenderer: (aggregates: Record<string, string>) =>
`<div style="padding: 6px; text-align: right;">Total ${aggregates['sum']}<br>Largest sale ${aggregates['max']}</div>`
}
];
// A group's header: its value and how many rows it holds. The typings declare data as a
// plain object; it holds the group's rows (subItems, with the group's totals rows marked
// totalsrow when showgroupaggregates is on) and, when grouped by more than one column,
// its subgroups.
readonly groupsrenderer = (
_text?: string,
group?: unknown,
_expanded?: boolean,
data?: object
): string => {
const { subItems = [], subGroups = [] } = data as {
subItems?: { totalsrow?: boolean }[];
subGroups?: unknown[];
};
const rows = subItems.filter((row) => !row.totalsrow).length;
return `<div style="padding: 6px 4px;"><strong>${group}</strong> (${subGroups.length ? `${subGroups.length} groups` : `${rows} sales`})</div>`;
};
// Grouping from the app's own control (the grid's header also takes drag and drop).
groupBy(field: string): void {
this.groupedBy.set(field);
const grid = this.grid();
grid.cleargroups();
if (field) {
grid.addgroup(field);
}
}
}
src/app/app.html:
<h1>Sales</h1>
<p>
<label>
Group by
<select #groupField [value]="groupedBy()" (change)="groupBy(groupField.value)">
<option value="">Nothing</option>
<option value="category">Category</option>
<option value="region">Region</option>
<option value="product">Product</option>
</select>
</label>
<button type="button" (click)="grid.expandallgroups()">Expand all</button>
<button type="button" (click)="grid.collapseallgroups()">Collapse all</button>
</p>
<jqxGrid #grid
[theme]="'fluent'"
[width]="'100%'"
[height]="480"
[source]="source"
[columns]="columns"
[groupable]="true"
[groups]="initialGroups"
[groupsrenderer]="groupsrenderer"
[showgroupsheader]="true"
[showaggregates]="true"
[showgroupaggregates]="true"
[showstatusbar]="true"
[statusbarheight]="70">
</jqxGrid>
The grid opens grouped by category: Beverages (40 sales), Condiments (20 sales), Seafood (40 sales) and Dairy (20 sales). The status bar shows the units sold (2940, an average of 24.5 per sale, 45 large sales) and the revenue (Total $57,320, Largest sale $1,408). Expand all opens the groups, each with its totals row at the end. Pick Region to group by region instead: four groups of 30 sales.