columns.groupHeaderTemplate String|Function

The template which renders the group header when the grid is grouped by the column field. By default the name of the field and the current group value is displayed.

The fields which can be used in the template are:

  • value - the current group value
  • field - the current group field
  • 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)
  • aggregates - provides access to all available aggregates, e.g. aggregates.fieldName1.sum or aggregates.fieldName2.average
  • items - the data items for current group. Returns groups if the data items are grouped (in case there are child groups)

Important To use aggregates from other fields in the column.groupHeaderTemplate add them to the other columns.aggregates.

Example - set the group header template

<div id="grid"></div>
<script>
 var grid = $("#grid").kendoGrid({
    groupable: true,
    columns: [
        { field: "name" },
        {
            field: "age",
            groupHeaderTemplate: "Age:#= value # total: #= count # Max Year: #= aggregates.year.max #",
            aggregates: ["count"]
        },
        { field: "year", aggregates: ["max"] }
    ],
    dataSource: {
        data: [
            { name: "Jane Doe", age: 30, year: 1978 },
            { name: "John Doe", age: 30, year: 1980 }
        ],
        group: {
            field: "age", aggregates: [{ field: "age", aggregate: "count" },
            { field: "age", aggregate: "max" }, { field: "year", aggregate: "max" }]
        }
    }
}).data("kendoGrid");
</script>

Example - use items field inside the group header template

<div id="grid"></div>
<script>
var filterAdmins = function(item) {
  return item.role === "admin";
};
$("#grid").kendoGrid({
  columns: [
    { field: "name" },
    { field: "age",
      groupHeaderTemplate: "Admin count: #=items.filter(filterAdmins).length#"
    },
    {field: "role" }
  ],
  dataSource: {
    data: [
      { name: "Jane Doe", age: 30, role: "admin" },
      { name: "John Doe", age: 30, role: "guest" },
      { name: "Peter", age: 30, role: "admin" }
    ],
    group: { field: "age", aggregates: [ { field: "age", aggregate: "count" }] }
  }
});
</script>
In this article
Not finding the help you need? Improve this article