In the Kendo Grid, it looks like we can group the data by multiple columns so that we have multiple levels of grouping. However, when we apply an aggregate, currently it is being applied at all the grouping levels. So, can someone please let me know if I can have different aggregates for different group levels. For example, if we have grouped data by say two columns, “UnitsInStock” and “UnitsOnOrder”, is it possible to show say Count of “ProductName” at the “UnitsOnOrder” grouping level and may be Sum of “UnitPrice” at the “UnitsInStock” group.
Following is the snippet that shows how I am doing the grouping in Kendo grid.
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products"
},
schema:{
model: {
fields: {
UnitsInStock: { type: "number" },
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsOnOrder: { type: "number" },
UnitsInStock: { type: "number" }
}
}
},
pageSize: 100,
group: [{
field: "UnitsInStock", aggregates: [
{ field: "UnitPrice", aggregate: "sum"},
]
},
{ field: "UnitsOnOrder", aggregates: [
{ field: "ProductName", aggregate: "count" },
{ field: "UnitPrice", aggregate: "sum"},
{ field: "UnitsOnOrder", aggregate: "sum" },
{ field: "UnitsInStock", aggregate: "count" }
]
}],
aggregate: [ { field: "ProductName", aggregate: "count" },
{ field: "UnitPrice", aggregate: "sum" },
{ field: "UnitsOnOrder", aggregate: "sum" },
{ field: "UnitsInStock", aggregate: "min" },
{ field: "UnitsInStock", aggregate: "max" }]
},
sortable: true,
scrollable: false,
pageable: true,
groupable:false,
columns: [
{ field: "ProductName", title: "Product Name", aggregates: ["count", "average" ], footerTemplate: "Total Count: #=count#", groupFooterTemplate: "Count: #=count#" },
{ field: "UnitPrice", title: "Unit Price", aggregates: ["sum"],footerTemplate: "Sum: #=sum#",
groupFooterTemplate: "Sum: #=sum#" },
{ field: "UnitsOnOrder", title: "Units On Order", aggregates: ["average", "sum"], footerTemplate: "Sum: #=sum#",
groupFooterTemplate: "Sum: #=sum#" },
{ field: "UnitsInStock", title: "Units In Stock", aggregates: ["min", "max", "count", "average"], footerTemplate: "<div>Min: #= min #</div><div>Max: #= max #</div>",
groupHeaderTemplate: "Units In Stock: #= value # " +
"(Sum: #= aggregates.UnitPrice.sum #)" }
]
});
});
</script>
Looking forward to your suggestions.
Thank You
Following is the snippet that shows how I am doing the grouping in Kendo grid.
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
type: "odata",
transport: {
read: "http://demos.telerik.com/kendo-ui/service/Northwind.svc/Products"
},
schema:{
model: {
fields: {
UnitsInStock: { type: "number" },
ProductName: { type: "string" },
UnitPrice: { type: "number" },
UnitsOnOrder: { type: "number" },
UnitsInStock: { type: "number" }
}
}
},
pageSize: 100,
group: [{
field: "UnitsInStock", aggregates: [
{ field: "UnitPrice", aggregate: "sum"},
]
},
{ field: "UnitsOnOrder", aggregates: [
{ field: "ProductName", aggregate: "count" },
{ field: "UnitPrice", aggregate: "sum"},
{ field: "UnitsOnOrder", aggregate: "sum" },
{ field: "UnitsInStock", aggregate: "count" }
]
}],
aggregate: [ { field: "ProductName", aggregate: "count" },
{ field: "UnitPrice", aggregate: "sum" },
{ field: "UnitsOnOrder", aggregate: "sum" },
{ field: "UnitsInStock", aggregate: "min" },
{ field: "UnitsInStock", aggregate: "max" }]
},
sortable: true,
scrollable: false,
pageable: true,
groupable:false,
columns: [
{ field: "ProductName", title: "Product Name", aggregates: ["count", "average" ], footerTemplate: "Total Count: #=count#", groupFooterTemplate: "Count: #=count#" },
{ field: "UnitPrice", title: "Unit Price", aggregates: ["sum"],footerTemplate: "Sum: #=sum#",
groupFooterTemplate: "Sum: #=sum#" },
{ field: "UnitsOnOrder", title: "Units On Order", aggregates: ["average", "sum"], footerTemplate: "Sum: #=sum#",
groupFooterTemplate: "Sum: #=sum#" },
{ field: "UnitsInStock", title: "Units In Stock", aggregates: ["min", "max", "count", "average"], footerTemplate: "<div>Min: #= min #</div><div>Max: #= max #</div>",
groupHeaderTemplate: "Units In Stock: #= value # " +
"(Sum: #= aggregates.UnitPrice.sum #)" }
]
});
});
</script>
Looking forward to your suggestions.
Thank You