Vue 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, a custom one, for each group and for the whole table.

Use a Vite and Vue 3 app set up as in Add a Grid to a Vue 3 app.
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.
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 totals rows are in subItems and subGroups too, marked totalsrow, so the counts leave them out:
// A group's header: its value and how many rows it holds. data holds the group's rows
// (subItems) and, when grouped by more than one column, its subgroups (subGroups). With
// showgroupaggregates on, both also hold the group's totals rows, marked totalsrow, which the
// counts leave out.
function groupsrenderer(_text: string, group: unknown, _expanded: boolean, data: { subItems?: { totalsrow?: boolean }[]; subGroups?: { totalsrow?: boolean }[] }) {
const { subItems = [], subGroups = [] } = data;
const rows = subItems.filter((row) => !row.totalsrow).length;
const groups = subGroups.filter((sub) => !sub.totalsrow).length;
return `<div style="padding: 6px 4px;"><strong>${group}</strong> (${groups ? `${groups} 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, and showgroupaggregates for each group.
aggregatesrenderer decides how the totals in the status bar are written. The values it receives are already formatted with the column's cellsformat, so the revenue total arrives as $57,320. A group's totals row does not use it: it shows the column's aggregates in the grid's own format, such as Sum:$18,140.
const columns = [
{ 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 ("$73,560").
aggregatesrenderer: (aggregates: Record<string, string>) =>
`<div style="padding: 6px; text-align: right;">Total ${aggregates.sum}<br>Largest sale ${aggregates.max}</div>`
}
];
A select of the component's own, bound with v-model, groups by another column: a watcher calls cleargroups, which removes the grouping, and addgroup, which adds a column to it. The buttons call expandallgroups and collapseallgroups through the template ref.
// Grouping from the app's own control (the grid's header also takes drag and drop).
watch(groupedBy, (field) => {
const g = grid.value;
if (!g) {
return;
}
g.cleargroups();
if (field) {
g.addgroup(field);
}
});
The new value of groupedBy re-renders the component, and JqxGrid's props are all constants, so the grid is not re-rendered and keeps the new grouping. Re-rendered, the Grid component would apply all its props again, among them source and the starting groups, category.
<template>
<main style="padding: 16px">
<h1>Sales</h1>
<p style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
<label>
Group by
<select v-model="groupedBy">
<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>
<!-- Every prop is a constant: a new grouping re-renders this component, not the grid,
which would otherwise apply groups (['category']) again. -->
<JqxGrid
ref="grid"
width="100%"
:height="480"
theme="material-purple"
:source="source"
:columns="columns"
:groupable="true"
:groups="initialGroups"
:groupsrenderer="groupsrenderer"
:showgroupsheader="true"
:showaggregates="true"
:showgroupaggregates="true"
:showstatusbar="true"
:statusbarheight="70"
/>
</main>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue';
import JqxGrid from 'jqwidgets-scripts/jqwidgets-vue3/vue_jqxgrid.vue';
// Defined globally by the jQWidgets core, which the Grid component imports.
declare const jqx: any;
interface Sale {
id: number;
region: string;
category: string;
product: string;
units: number;
revenue: number;
}
// The grid methods this component calls.
interface GridMethods {
cleargroups: () => void;
addgroup: (datafield: string) => void;
expandallgroups: () => void;
collapseallgroups: () => void;
}
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 };
});
const 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' }
]
});
const columns = [
{ 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 ("$73,560").
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. data holds the group's rows
// (subItems) and, when grouped by more than one column, its subgroups (subGroups). With
// showgroupaggregates on, both also hold the group's totals rows, marked totalsrow, which the
// counts leave out.
function groupsrenderer(_text: string, group: unknown, _expanded: boolean, data: { subItems?: { totalsrow?: boolean }[]; subGroups?: { totalsrow?: boolean }[] }) {
const { subItems = [], subGroups = [] } = data;
const rows = subItems.filter((row) => !row.totalsrow).length;
const groups = subGroups.filter((sub) => !sub.totalsrow).length;
return `<div style="padding: 6px 4px;"><strong>${group}</strong> (${groups ? `${groups} groups` : `${rows} sales`})</div>`;
}
const initialGroups = ['category'];
const grid = ref<GridMethods | null>(null);
const groupedBy = ref('category');
// Grouping from the app's own control (the grid's header also takes drag and drop).
watch(groupedBy, (field) => {
const g = grid.value;
if (!g) {
return;
}
g.cleargroups();
if (field) {
g.addgroup(field);
}
});
</script>
<template>
<main style="padding: 16px">
<h1>Sales</h1>
<p style="display: flex; flex-wrap: wrap; gap: 8px; align-items: center">
<label>
Group by
<select v-model="groupedBy">
<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>
<!-- Every prop is a constant: a new grouping re-renders this component, not the grid,
which would otherwise apply groups (['category']) again. -->
<JqxGrid
ref="grid"
width="100%"
:height="480"
theme="material-purple"
:source="source"
:columns="columns"
:groupable="true"
:groups="initialGroups"
:groupsrenderer="groupsrenderer"
:showgroupsheader="true"
:showaggregates="true"
:showgroupaggregates="true"
:showstatusbar="true"
:statusbarheight="70"
/>
</main>
</template>
The grid opens grouped by category, with the groups closed: Beverages (40 sales), Condiments (20 sales) and so on. Open one with its arrow, or with Expand all, to see its sales followed by its totals row. The status bar shows Sum:2940, Avg:24.5 and Large sales:45 under Units, and Total $57,320 and Largest sale $1,408 under Revenue. Pick Region to group by region instead.