I have a grid with two columns ie Type & Size. I want to sum of all sizes on group header when I want to do group by type. Please see my sample code below.
Type size
gif 10
gif 20
PNG 30
PNG 15
Result after doing group by Type :
Gif (Sum of sizes) --30
PNG (Sum of sizes) --45
Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery.min.js" type="text/javascript"></script>
<script src="Scripts/kendo.web.min.js" type="text/javascript"></script>
<link href="styles/kendo.common.min.css" rel="stylesheet" type="text/css" />
<link href="styles/kendo.default.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="grid"></div>
<script>
var pictures = [
{
type: "JPG",
size: 10
}, {
type: "JPG",
size: 20
}, {
type: "JPG",
size: 12
}, {
type: "JPG",
size: 10
}, {
type: "JPG",
size: 10
}, {
type: "JPG",
size: 20
}, {
type: "JPG",
size: 20
}, {
type: "JPG",
size: 10
}, {
type: "JPG",
size: 12
}, {
type: "JPG",
size: 10
}, {
type: "JPG",
size: 1
}, {
type: "JPG",
size: 10
}, {
type: "JPG",
size: 12
}, {
type: "JPG",
size: 20
}, {
type: "JPG",
size: 20
}, {
type: "PNG",
size: 10
}, {
type: "PNG",
size: 10
}, {
type: "PNG",
size: 10
}, {
type: "PNG",
size: 20
}, {
type: "PNG",
size: 20
}, {
type: "PNG",
size: 12
}, {
type: "PNG",
size: 10
}, {
type: "PNG",
size: 20
}, {
type: "PNG",
size: 20
}, {
type: "PNG",
size: 12
}, {
type: "PNG",
size: 12
}, {
type: "PNG",
size: 10
},
{
type: "GIF",
size: 25
},
{
type: "GIF",
size: 35
},
];
var dataSource = new kendo.data.DataSource({
data: pictures
});
$(document).ready(function () {
$("#grid").kendoGrid({
dataSource: dataSource,
columns: [
{
field: "type",
aggregates: "count",
groupHeaderTemplate: "Type: #= value # Count: #= count #"
},
{
field: "size",
aggregates: ["count", "sum"],
groupHeaderTemplate: "Grouped by size: #= value # Count: #= count #, Sum: #= sum#"
}
],
groupable: true
});
});
</script>
</body>
</html>