Angular Grid Selection Aggregates
The Grid enables you to select single or multiple cells or rows and calculate different metrics based on the selected data.
This functionality allows you to get a quick snapshot of some of the more important aggregates of the selected data. You can use the built-in approach and display these metrics at the bottom of the Grid or create your own elements that would display the data.
The Grid supports the following built-in aggregates for all selected cells:
max
—the greatest number. Valid for numeric fields.min
—the smallest number. Valid for numeric fields.sum
—the sum of all numbers. Valid for numeric fields.average
—the average of all numbers. Valid for numeric fields.count
—the total number of cells.earliest
—the earliest date. Valid forDate
fields.latest
—the latest date. Valid forDate
fields.isTrue
—the total number of boolean fields withtrue
value.isFalse
—the total number of boolean fields withfalse
value.
Setup
To enable the selection aggregates of the Grid:
-
Set the
selectable
property to aSelectableSettings
object where thecellAggregates
option is set to:true
—Calculates all selection aggregates.tspublic selectableSettings: SelectableSettings = { ... cellAggregates: true, };
SelectionAggregate
—Calculates specific aggregates.tspublic selectableSettings: SelectableSettings = { ... cellAggregates: ['min', 'max', 'count'], x };
-
The Grid can handle the calculation of the selection aggregates, but does not show the result automatically. To display the aggregates in a dedicated status bar below the Grid, utilize the built-in
StatusBarTemplateDirective
.ts<ng-template kendoGridStatusBarTemplate let-aggregates="aggregates"> <div *ngFor="let aggr of aggregates | keyvalue : originalOrder"> <span class="k-selection-aggregates-item-text"> {{ aggr.key }}: </span> <span class="k-selection-aggregates-item-value"> {{ displayAggregates(aggr) }} </span> </div> </ng-template>
There are two utility classes coming from the Kendo Themes that can be used to style the text and value of the cell selection aggregates. Use the
k-selection-aggregates-item-text
class for the name of the aggregate and thek-selection-aggregates-item-value
class for its value.
The following example demonstrates how to display the aggregate values with the StatusBarTemplateDirective
.
Displaying Selection Aggregates Externally
To display the aggregates within a custom element or component, handle the Grid selectionChange
event and access the precalculated aggregates from the exposed event data.
The following example demonstrates how to display the selection aggregates in a custom element.