How to Group multiple columns and display the Count on the Kendogrid-Angular application

1 Answer 1985 Views
General Discussions
Siva
Top achievements
Rank 1
Siva asked on 09 May 2018, 10:24 PM
We are trying to Group multiple columns and display the Count on the Kendogrid-Angular application. Attached is the sample grid. Please help.

1 Answer, 1 is accepted

Sort by
0
Svet
Telerik team
answered on 11 May 2018, 10:52 AM
Hi Siva,

We can calculate the required group aggregates by using a proper GroupDescriptor:

public groups: GroupDescriptor[] = [{ field: 'Category.CategoryName', aggregates: [{aggregate: "count", field: 'Category.CategoryName'}]},{ field: 'UnitPrice', aggregates: [{aggregate: "count", field: "UnitPrice"}] }];

Once we have defined the group descriptors we can process the data so that the grid groups the data and calculates the aggregates:

private loadProducts(): void {
    this.gridView = process(products, { group: this.groups });
}

Finally we can use the kendoGridGroupHedearTemplate directive in order to display specific messages containing the aggregates in the group headers:

<ng-template kendoGridGroupHeaderTemplate let-value="value" let-aggregates="aggregates" let-field="field">
<strong>{{value + " Count"}}</strong>: {{aggregates[field].count}}
</ng-template>

Check the following example demonstrating this approach:

https://stackblitz.com/edit/kendo-grouped-grid-3-ptfrzu

I hope this helps.

Regards,
Svetlin
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
General Discussions
Asked by
Siva
Top achievements
Rank 1
Answers by
Svet
Telerik team
Share this question
or