ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

ui-grid footer sum double counts by including the subtotals when grouping is applied

Open miah-al opened this issue 11 years ago • 10 comments

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

miah-al avatar Jun 19 '15 15:06 miah-al

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

AgDude avatar Jun 19 '15 16:06 AgDude

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.

miah-al avatar Jun 19 '15 17:06 miah-al

Thanks for clarifying.

AgDude avatar Jun 19 '15 18:06 AgDude

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.

miah-al avatar Jun 24 '15 22:06 miah-al

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

AgDude avatar Jun 25 '15 14:06 AgDude

Hi,

I just verified the latest fix. There seems to be a small issue

  1. When aggregationType: uiGridConstants.aggregationTypes.sum is there in the column template, it double counts.
  2. 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

miah-al avatar Jul 01 '15 14:07 miah-al

@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.

AgDude avatar Jul 01 '15 15:07 AgDude

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

miah-al avatar Jul 01 '15 15:07 miah-al

@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.

AgDude avatar Jul 01 '15 16:07 AgDude

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 :(.

miah-al avatar Jul 01 '15 17:07 miah-al