我有kendo grid javascript分组如下
group: {
field: "ResourceName",
aggregates: [
{ field: "WeekOneUtilization", aggregate: "sum" },
{ field: "WeekTwoUtilization", aggregate: "sum" },
{ field: "WeekThreeUtilization", aggregate: "sum" },
{ field: "WeekFourUtilization", aggregate: "sum" }
]
},
aggregate: [{ field: "ProjectName", aggregate: "count" },
{ field: "WeekOneUtilization", aggregate: "sum" },
{ field: "WeekTwoUtilization", aggregate: "sum" },
{ field: "WeekThreeUtilization", aggregate: "sum" },
{ field: "WeekFourUtilization", aggregate: "sum" }]
我希望获得四周的总和
结果如下
答案 0 :(得分:2)
你的代码是用JavaScript完成的,这真是太棒了......现在你可能是最接近上帝(你的网格)的东西...所以让我们来吧工作
1)转到你的数据源模型,并在那里定义一些方便的计算的东西......例如。
var yourDataSource = new kendo.data.DataSource({
schema:{
model: {
// Typical blah blah here
id: 'your-id-field',
fields: {
// Typical field declaration blah blah
},
// This handy function will calculate
// the sum of the 4 weeks in your row
sumOfAllWeeks: function(){
return this.get('WeekOneUtilization') +
this.get('WeekTwoUtilization') +
this.get('WeekThreeUtilization') +
this.get('WeekFourUtilization');
}
}
}
});
2)现在你可以将这个闪亮的全新计算字段添加到你的聚合配置中,语法有点不同。
{ field: "sumOfAllWeeks()", aggregate: "sum" }
3)但是,如果你想让kendo处理网格中计算属性的聚合,就会出现一个错误(可能现在已修复)......他错误地试图调用你的字段名称" sumOfAllWeeks( )"作为一个函数而不是累加器,不像他用普通场。因此,在您的网格中,您必须将模板用作函数。
让我们通过在您的网格中为您的计算机创建一个新列来说明这一点......
// Your grid fields declaration
columns:[
// Here you may have your columns declared,
// as shown in your picture... so I save the blah blah
// Now we declare a column for your computed.
{
field: 'sumOfAllWeeks()',
aggregates: 'sum',
// This handles the group footer template
groupFooterTemplate: function(data){
return data['sumOfAllWeeks()'].sum;
},
// This handles the table footer template
footerTemplate: function(data){
return data['sumOfAllWeeks()'].sum;
}
}
]
答案 1 :(得分:0)
您可以使用ClientTemplate
:
columns.Bound(p => p.Total).ClientTemplate("#= WeekOneUtilization + WeekTwoUtilization + WeekThreeUtilization + WeekFourUtilization #");