API REFERENCE · DATA GRID PLUGINS
@dojo-ng/data-grid-groups
Row grouping with aggregates for <dj-data-grid>.
npm install @dojo-ng/data-grid-groups
Group rows show the value and count; aggregated columns show sums (or mean/min/max/count/custom). A totals row renders below the grid.
<dj-data-grid id="g"></dj-data-grid>
<script type="module">
import "@dojo-ng/data-grid";
import { groupsPlugin } from "@dojo-ng/data-grid-groups";
const g = document.getElementById("g");
g.columns = [
{ id: "region", header: "Region" },
{ id: "product", header: "Product" },
{ id: "sales", header: "Sales" },
];
g.data = [
{ region: "West", product: "Widget", sales: 100 },
{ region: "West", product: "Gadget", sales: 50 },
{ region: "East", product: "Widget", sales: 75 },
];
g.plugins = [groupsPlugin({ by: "region", aggregates: { sales: "sum" } })];
</script>
Grouping
bylists the columns to group by. A grouped row shows an expander, the group value, and the number of rows in the group, such asAda (3).- That count is always there. You do not need a
countaggregate to get it.
Aggregates
aggregatessets an aggregate per column:sum,mean,min,max,count, or a function over the group's rows.- A
countaggregate on another column shows the same number again in that column. Use it for a separate count column, not just to see the size of each group. - When
aggregatesis set, a grand-totals row appears below the rows. - Numeric aggregates are formatted through
@dojo-ng/i18n, so they follow the grid's locale.
Rules
- Use
groupsPluginortreePluginon a grid, never both. Both control row expansion, so setup throws an error if both are present.
Functions
groupsPlugin
function groupsPlugin({ by, aggregates }: GroupsOptions): DataGridPlugin;
Types
Aggregate
type Aggregate = "sum" | "mean" | "min" | "max" | "count" | ((rows: TableRow<Row>[]) => unknown);
GroupsOptions
interface GroupsOptions {
by: string | string[];
aggregates?: Record<string, Aggregate>;
}