This is a migrated thread and some comments may be shown as answers.

Multiple fields in groupHeaderTemplate

6 Answers 1343 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 02 May 2013, 06:42 PM
Hello,

Is it possible to build a group header template that displays information from multiple fields? I tried various approaches but cannot get it to work. For example, I defined a new column with a template that includes multiple fields, but it is not shown when grouping by it unless I provide a field value that exists in the data source. Even then the template is not used for the group header. I can see the logic of this, but I can't find another way.

Thanks,
Gary

6 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 03 May 2013, 08:32 AM
Hello Gary,

 All fields available in the groupHeaderTemplate are listed in the documentation:

The fields which can be used in the template are:

  • value - the current group value
  • average - the value of the "average" aggregate (if specified)
  • count - the value of the "count" aggregate (if specified)
  • max - the value of the "max" aggregate (if specified)
  • min - the value of the "min" aggregate (if specified)
  • sum - the value of the "sum" aggregate (if specified)

You cannot use fields which aren't in this list.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gary
Top achievements
Rank 1
answered on 03 May 2013, 01:45 PM
Hello Atanas,

Yes, I did already review the documentation and I should have pointed that out in my original post. That is why I described one attempt of specifying the template on the column to include multiple fields. I also tried adding a calculated field in the data source model, but that produced an empty field.

To explain this better, my data source includes two fields that I would like to combine together into a single grid column that I will then group on.

I expect this can be done, but I cannot find the right syntax to accomplish it.

Thanks for your help.
Gary
0
Atanas Korchev
Telerik team
answered on 03 May 2013, 02:07 PM
Hi Gary,

It should be possible to implement grouping by a computed field like this: http://jsbin.com/ubifok/2/edit

However you still won't be able to access more than the current group value in the group header template.

All the best,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
loi
Top achievements
Rank 1
answered on 06 Jun 2013, 10:59 PM
We've done this before for a grid with ajax datasource.  I think it is possible if you call a custom client function inside the ClientGroupHeaderTemplate. Here are snippets of the code we used.

<script type="text/javascript">
 
    var $MyApp = {
            Document: {
                groupHeaderTemplate : kendo.template("*Document: #= DocumentName #  #if (DocPersonOrEntityName != null)) {# *For: #= DocPersonOrEntityName #  #}# "),
 
                renderGroupHeaderText: function(documentID){
                    var theGridData = $("#gridID").data("kendoGrid").dataSource.data();
 
                    var doc = $.grep(
                        theGridData,
                        function(item,indx){
                            return (item.DocumentID == documentID);
                        }
                    )[0];//get the first record
 
                    return $MyApp.Document.groupHeaderTemplate(doc.toJSON());
                }  
            }
        };
 
</script>

columns.Bound(o => o.DocumentID)
    .Title("")
    .Hidden(true)
    .ClientGroupHeaderTemplate(" #= $MyApp.Document.renderGroupHeaderText(value) # ");
0
Kyle
Top achievements
Rank 2
Veteran
answered on 20 Feb 2014, 04:01 PM
[quote]loi said:We've done this before for a grid with ajax datasource.  I think it is possible if you call a custom client function inside the ClientGroupHeaderTemplate. Here are snippets of the code we used...[/quote]
loi,

This was EXACTLY what I needed.  I wish I could give you rep or something.  Thank you!
0
Daniel
Top achievements
Rank 1
answered on 20 Apr 2015, 11:31 AM

Hi Atanas, 

Is it possible to use aggregate outside grid ?

like in the Mobile Custom Templates (http://demos.telerik.com/kendo-ui/mobile-listview/templates)

I want to put more information in the header like how many items in that group.

your help is much appreciate.

Tags
Grid
Asked by
Gary
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Gary
Top achievements
Rank 1
loi
Top achievements
Rank 1
Kyle
Top achievements
Rank 2
Veteran
Daniel
Top achievements
Rank 1
Share this question
or