ui-grid footer sum double counts by including the subtotals when grouping is applied
Looks like ui-grid is including the subtotals in the footer sum. It should only sum up the base cell values.
http://plnkr.co/edit/nQ2X3OnYAj43uQaXHTHV?p=preview
I am not seeing the problem you describe in the plunker. Did you maybe find this bug in an older version?
Here is an updated version with only a few rows, so it is easier to see what totals should be: http://plnkr.co/edit/Wq3EfNHA7cnmaZ9ZQt61?p=preview
Hi,
Thanks for the response. I am using the latest version. I can reproduce in your plunker. Please expand the rows by clicking the + sign, you will see the wrong total at the bottom.
Thanks for clarifying.
Is there any workaround for this? I mean is there a way to hide the totals when grouping is turned on. Thanks in advance for your help.
You could certainly turn off aggregation in the same callback you use to enable grouping.
Or do you mean hide only when there are actually grouped columns? There isn't currently an event api for grouping changes (I just opened #3868 to add one). You could use the rowExpanded event from treebase, since it this problem only occurs when there are expanded rows.
http://ui-grid.info/docs/#/api/ui.grid.treeBase.api:PublicApi
Hi,
I just verified the latest fix. There seems to be a small issue
- When aggregationType: uiGridConstants.aggregationTypes.sum is there in the column template, it double counts.
- When aggregationType: uiGridConstants.aggregationTypes.sum is not there in the column template, it does not double count but it does not show any totals at the bottom when all the groupings are removed.
Again, thanks everyone contributing to this awesome library.
http://plnkr.co/edit/Wq3EfNHA7cnmaZ9ZQt61?p=preview
@alam123 The grouping aggregation and the base grid aggregation use very different systems for calculation, so they can't use the same functions. Please see the api docs for more details.
Currently grouping only applies the footer aggregation if it isn't applied at the grid level, I will take another look and consider whether that should change.
One could in theory write an adapter function which would take the grouping function and apply it as a base aggregation function, which could then be applied when grouping is added/removed. I will try to implement the events on grouping soon, so that is easier to hook into.
Sorry, I had mentioned the wong plunk. The following illustrates the issue. http://plnkr.co/edit/a3yD0MyhiXPbRKcrqZ8F?p=preview
The same behavior is in the tutorial
http://ui-grid.info/docs/#/tutorial/320_complex_grouping
@alam123 I just merged a change with events for grouping. This tutorial has an example: http://ui-grid.info/docs/#/tutorial/320_complex_grouping.
docs: http://ui-grid.info/docs/#/api/ui.grid.grouping.api:PublicApi
Basically, you should hook into those events and add/remove any of your grid level aggregations. If you do write a flexible function for using the grouping aggregation functions at the grid level, please share it.
Thanks @AgDude I just did a custom sum to fix this issue at my end. Please look at the behaviour of the last column and the sum at the bottom when you expand the rows and then remove all the groupings.
http://plnkr.co/edit/QUy1bDuA3jPWVrLVyLP5?p=preview
Edit: If you start without any grouping the totals at the bottom wont show :(.