在我的情况下,我必须分组为剑道网格并以编程方式执行各组的总和。
就我而言,我可以使用以下代码将代码直接存储在网格中:
group: [{ field: "age", aggregates: [ { field: "age", aggregate: "sum" }] }]
如何以编程方式将其存储为代码?
答案 0 :(得分:0)
我的解决方案如下:
<div id="grid"></div>
<script>
var dataSource = new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 },
{ name: "Jane Doo", age: 30 },
{ name: "John Doe", age: 33 }
]
});
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
groupable: true,
columns: [
{
field: "name"
},
{
field: "age",
// groupFooterTemplate: "Total: #= sum #"
}
],
}).data("kendoGrid");
grid.dataSource.group([
{ field: "age", aggregates: [
{ field: "age", aggregate: "sum" }
]
}
]);
$.each(grid.columns, function(key, vs){
console.log(grid.columns[key].field);
if(grid.columns[key].field == "age"){
grid.columns[key].groupFooterTemplate = "Total: #= sum #";
}
});
grid.refresh();
</script>
如果有更好的解决方案,我很高兴接管他们。