Multi column grouping in Kendo Grid

Nupur picture Nupur · Sep 2, 2015 · Viewed 12.4k times · Source

I am using kendo grid to display a set of records. But now I want to use Aggregates property to group columns and perform certain aggregate function on columns.

As per the below documentation,I can apply grouping on a single column,but I want to do grouping on multi column http://demos.telerik.com/kendo-ui/grid/aggregates

Please suggest how can I acheive it.

Thanks

Answer

Atanas Korchev picture Atanas Korchev · Sep 2, 2015

You need to set the group option of the grid's data source as array. Here is some sample code:

  <div id="grid"></div> 
  <script>
    var dataSource = new kendo.data.DataSource({
      data: [
        { name: "Pork", category: "Food", subcategory: "Meat" },
        { name: "Pepper", category: "Food", subcategory: "Vegetables" },
        { name: "Beef", category: "Food", subcategory: "Meat" }
      ],
      group: [
        // group by "category" and then by "subcategory"
        { field: "category" },
        { field: "subcategory" },
      ]
    });
    $("#grid").kendoGrid({
      dataSource: dataSource
    });
  </script>

Here is a live demo: http://dojo.telerik.com/@korchev/OBAva