admin管理员组文章数量:1023744
I have kendo grid java script grouping as follows
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" }]
I want to get Sum of sums of four weeks
the result is as follows
I have kendo grid java script grouping as follows
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" }]
I want to get Sum of sums of four weeks
the result is as follows
Share Improve this question edited Mar 12, 2015 at 6:25 udaya726 asked Mar 12, 2015 at 6:14 udaya726udaya726 1,0107 gold badges24 silver badges44 bronze badges2 Answers
Reset to default 2Your code is done in JavaScript so that's awesome... now you're the closest thing to god (of your grid) as you could be... so let's get to work.
1) Go to your datasource's model, and define some handy puted things there... for example.
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) Now you can just add this shiny brand new puted field into your aggregates configuration, the syntax is a bit different.
{ field: "sumOfAllWeeks()", aggregate: "sum" }
3) However, there is a bug (maybe its fixed now) if you want to just let kendo deal with aggregates of puted properties in your grid... he mistakenly tries to invoke your field name "sumOfAllWeeks()" as a function instead of an accumulator, unlike he does with a plain field. So in your grid, you have to use the templates as a function.
Let's illustrate this by creating a new column for your puted, in your grid, like this...
// 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 puted.
{
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;
}
}
]
You can use a ClientTemplate
for this:
columns.Bound(p => p.Total).ClientTemplate("#= WeekOneUtilization + WeekTwoUtilization + WeekThreeUtilization + WeekFourUtilization #");
I have kendo grid java script grouping as follows
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" }]
I want to get Sum of sums of four weeks
the result is as follows
I have kendo grid java script grouping as follows
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" }]
I want to get Sum of sums of four weeks
the result is as follows
Share Improve this question edited Mar 12, 2015 at 6:25 udaya726 asked Mar 12, 2015 at 6:14 udaya726udaya726 1,0107 gold badges24 silver badges44 bronze badges2 Answers
Reset to default 2Your code is done in JavaScript so that's awesome... now you're the closest thing to god (of your grid) as you could be... so let's get to work.
1) Go to your datasource's model, and define some handy puted things there... for example.
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) Now you can just add this shiny brand new puted field into your aggregates configuration, the syntax is a bit different.
{ field: "sumOfAllWeeks()", aggregate: "sum" }
3) However, there is a bug (maybe its fixed now) if you want to just let kendo deal with aggregates of puted properties in your grid... he mistakenly tries to invoke your field name "sumOfAllWeeks()" as a function instead of an accumulator, unlike he does with a plain field. So in your grid, you have to use the templates as a function.
Let's illustrate this by creating a new column for your puted, in your grid, like this...
// 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 puted.
{
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;
}
}
]
You can use a ClientTemplate
for this:
columns.Bound(p => p.Total).ClientTemplate("#= WeekOneUtilization + WeekTwoUtilization + WeekThreeUtilization + WeekFourUtilization #");
本文标签: javascriptSum of sum columns in kendo gridStack Overflow
版权声明:本文标题:javascript - Sum of sum columns in kendo grid - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745584601a2157512.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论