gpt4 book ai didi

javascript - 剑道网格中总和列的总和

转载 作者:行者123 更新时间:2023-11-30 17:00:18 26 4
gpt4 key购买 nike

我有剑道网格java脚本分组如下

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" }]

我想得到四个星期的总和

结果如下 enter image description here

最佳答案

您的代码是用 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) 现在您可以将这个 Shiny 的全新计算字段添加到您的聚合配置中,语法有点不同。

{ 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;
}
}
]

关于javascript - 剑道网格中总和列的总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29003002/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com