Ng-grid Sum Of Values In Aggregate Row
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 display
Solution 1:
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:
On my gridOptions I define the property shown below
aggregateTemplate: "<divng-click=\"row.toggleExpand()\" ng-style=\"rowStyle(row)\" class=\"ngAggregate\">" +
" <spanclass=\"ngAggregateText\"><spanclass='ngAggregateTextLeading'>{{row.totalChildren()}} {{row.label CUSTOM_FILTERS}} {{entryMaybePlural(row)}}</span><span>Total Weight: {{aggFunc(row)}} lbs {{AggItemsLabel}}</span></span>" +
" <divclass=\"{{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";
}
elsereturn"entry";
};
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 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
***********************************************/
Post a Comment for "Ng-grid Sum Of Values In Aggregate Row"