Skip to content

Commit f2368cc

Browse files
committed
Merge pull request #3907 from AgDude/agdude-grouping
Fix bugs in footer aggregation in grouping
2 parents b7002ba + 1127e62 commit f2368cc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/features/tree-base/js/tree-base.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,15 @@
13271327
* @param {array} parents the parents that we would want to aggregate onto
13281328
*/
13291329
aggregate: function( grid, row, parents ){
1330-
if ( parents.length === 0 ){
1331-
return;
1330+
if ( parents.length === 0 && row.treeNode && row.treeNode.aggregations ){
1331+
row.treeNode.aggregations.forEach(function(aggregation){
1332+
// Calculate aggregations for footer even if there are no grouped rows
1333+
if ( typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ) {
1334+
var fieldValue = grid.getCellValue(row, aggregation.col);
1335+
var numValue = Number(fieldValue);
1336+
aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
1337+
}
1338+
});
13321339
}
13331340

13341341
parents.forEach( function( parent, index ){
@@ -1338,7 +1345,7 @@
13381345
var numValue = Number(fieldValue);
13391346
aggregation.col.treeAggregationFn(aggregation, fieldValue, numValue, row);
13401347

1341-
if ( index === 0 && typeof aggregation.col.treeFooterAggregation !== 'undefined' ){
1348+
if ( index === 0 && typeof(aggregation.col.treeFooterAggregation) !== 'undefined' ){
13421349
aggregation.col.treeAggregationFn(aggregation.col.treeFooterAggregation, fieldValue, numValue, row);
13431350
}
13441351
});
@@ -1507,6 +1514,10 @@
15071514
*/
15081515
treeFooterAggregationType: function( rows, column ) {
15091516
service.finaliseAggregation(undefined, column.treeFooterAggregation);
1517+
if ( typeof(column.treeFooterAggregation.value) === 'undefined' || column.treeFooterAggregation.rendered === null ){
1518+
// The was apparently no aggregation performed (perhaps this is a grouped column
1519+
return '';
1520+
}
15101521
return column.treeFooterAggregation.rendered;
15111522
}
15121523
};

0 commit comments

Comments
 (0)