Skip to content

Commit 5140060

Browse files
committed
Doco(grouping): fix #3577 grouping tutorial getAggregates
1 parent 31d3972 commit 5140060

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

misc/tutorial/209_grouping.ngdoc

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,31 @@ function will stop working), and writes them to the console.
143143
};
144144

145145
$scope.getAggregates = function() {
146-
var aggregateInfo = {};
147-
var lastState;
148-
$scope.gridApi.grid.renderContainers.body.visibleRowCache.forEach( function(row) {
149-
if( row.groupHeader ) {
150-
if( row.groupLevel === 0 ){
151-
// in the format "xxxxx (10)", we want the xxxx and the 10
152-
if( match = row.entity.state.match(/(.+) \((\d+)\)/) ){
153-
aggregateInfo[ match[1] ] = { stateTotal: match[2] };
154-
lastState = match[1];
155-
}
156-
} else if (row.groupLevel === 1){
157-
if( match = row.entity.gender.match(/(.+) \((\d+)\)/) ){
158-
aggregateInfo[ lastState ][ match[1] ] = match[2];
146+
var aggregatesTree = [];
147+
var gender
148+
149+
var recursiveExtract = function( treeChildren ) {
150+
return treeChildren.map( function( node ) {
151+
var newNode = {};
152+
angular.forEach(node.row.entity, function( attributeCol ) {
153+
if( typeof(attributeCol.groupVal) !== 'undefined' ) {
154+
newNode.groupVal = attributeCol.groupVal;
155+
newNode.aggVal = attributeCol.value;
159156
}
157+
});
158+
newNode.otherAggregations = node.aggregations.map( function( aggregation ) {
159+
return { colName: aggregation.col.name, value: aggregation.value, type: aggregation.type };
160+
});
161+
if( node.children ) {
162+
newNode.children = recursiveExtract( node.children );
160163
}
161-
}
162-
});
163-
console.log(aggregateInfo);
164+
return newNode;
165+
});
166+
}
167+
168+
aggregatesTree = recursiveExtract( $scope.gridApi.grid.treeBase.tree );
169+
170+
console.log(aggregatesTree);
164171
};
165172
}])
166173
.filter('mapGender', function() {

0 commit comments

Comments
 (0)