Grid Client Group Header Template reference other field values in the row?

1 Answer 23 Views
Grid
Keith
Top achievements
Rank 1
Keith asked on 27 Jul 2021, 07:08 PM

I am using the Core Grid with grouping.  I am grouping on a field called "ClassOrder", but would like to display the name of the field called "Class" in the template.  The desired order of display is not alphabetical, but driven by that "ClassOrder" column. 

What is the syntax to use in the group header template to refer to other fields in the row?

 

Thx!

1 Answer, 1 is accepted

Sort by
0
Accepted
Stoyan
Telerik team
answered on 30 Jul 2021, 03:06 PM

Hi Keith,

The columnGroup header exposes the field name and the value of the dataItem by which the Grid is grouped. In addition if there are any aggregates applied to the data returned by the server, they are also available in the columnGroup header template. For more information I recommend the client-side API docs of the Grid's ColumnHeaderGroupTemplate.

One possible solution of the requirement at hand is to hard code the Name of the desired column:

// in the following example the Grid is grouped by OrderDate, however the GroupHeaderTemplate shows the name and data of the Freight column
columns.Bound(p => p.Freight);
columns.Bound(p => p.OrderDate).ClientGroupHeaderTemplate("Freight #=aggregates.Freight.count#");

I have applied the above to the attached sample project. Please let me know, if you have further questions. Thank you.

Regards,


Stoyan
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Keith
Top achievements
Rank 1
commented on 31 Jul 2021, 12:43 AM | edited

This works now. Using your sample I got things very close, then realized that to display a different field's value in the header (i.e., grouping by ClassOrder, but then displaying the text value of "Class", I needed to add "Class" to the aggregates set. To do so, I added a "max()" aggregate for Class, then in the header template included aggregates.Class.max() .
A little klunky, but it works beautifully.
Tags
Grid
Asked by
Keith
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Share this question
or