合计行值的NG-格求和 [英] ng-grid sum of values in aggregate row
问题描述
我有一个纳克网格具有从三个不同的计算机三列(名称,值机),其显示的指标(名称,值)(如在机柱表示)。而不是为每个指标显示三线,我已经设置组:['名']
在gridOptions;不过,我不能想出如何使总排显示值的总和。有没有一种方法来访问每个组中的行的值来计算总和?
I have an ng-grid with three columns (name, value, machine) that displays metrics (name, value) from three different computers (as indicated in machine column). Rather than displaying three lines for each metric, I have set groups: ['name']
in the gridOptions; however, I cannot figure out how to make the aggregate row display the sum of the values. Is there a way to access the values of the rows in each group to calculate a sum?
这是我所希望看到的(7,10,4,6日在值列聚合行):
This is what I want to see (7, 10, 4, 6 on the aggregate rows in the value column):
NAME VALUE MACHINE
v metric1 (3) 7
metric1 3 comp-a
metric1 2 comp-b
metric1 2 comp-c
> metric2 (3) 10
> metric3 (3) 4
v metric4 (3) 6
metric4 5 comp-a
metric4 0 comp-b
metric5 1 comp-c
感谢您的帮助!
推荐答案
我遇到了同样的问题,并尝试了一些提出的解决方案,我发现,但没有与电网我的版本工作。我搜索的栅源,发现矿用骨料行模板,复制然后将它调整为包括功能上的我的方法的显示部分的电话:
I ran into this same problem and tried some proposed solutions I found but wasn't working with the version of the grid I have. I searched the grid source and found the template that mine was using for aggregate rows and copied it then tweaked to include a call to a function on my method for parts of the display:
在我gridOptions我定义如下所示的属性
On my gridOptions I define the property shown below
aggregateTemplate: "<div ng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">" +
" <span class=\"ngAggregateText\"><span class='ngAggregateTextLeading'>{{row.totalChildren()}} {{row.label CUSTOM_FILTERS}} {{entryMaybePlural(row)}}</span><span>Total Weight: {{aggFunc(row)}} lbs {{AggItemsLabel}}</span></span>" +
" <div class=\"{{row.aggClass()}}\"></div>" +
"</div>" +
""
在控制器为网格的范围我有功能
On the scope of the controller for the grid I have the functions
$scope.aggFunc = function (row) {
var total = 0;
angular.forEach(row.children, function(cropEntry) {
total+=cropEntry.entity.weight;
});
return total.toString();
};
$scope.entryMaybePlural = function (row) {
if(row.children.length>1)
{
return "entries";
}
else
return "entry";
};
您会在两种情况下我通过该行的模板中的控制器范围的功能看,然后我看叫孩子们的财产在该行上(我只是想通了这一点使用Chrome的调试工具,当其他企图没有成功)。
You'll see in both cases I pass the row in the template to the function in the controller scope, then I look at the property called children on the row (I just figured this out using the Chrome debugging tools when other attempts didn't work out).
PS我的网格在顶部此编译评论,但没有版本:|
PS my grid has this compilation comment in the top, though no version :|
/***********************************************
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/03/2013 21:19
***********************************************/
这篇关于合计行值的NG-格求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!