ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: mikep on August 29, 2020, 02:52:13 am

Title: Row Totals for n-Columns
Post by: mikep on August 29, 2020, 02:52:13 am
Hi. I have a grid that displays a variable number of columns w/costs. What's the best way to have a column at the end of the grid that sums these columns?
In this example I have two columns that I need to sum, but it could be any number of columns

https://jsfiddle.net/cvbwstL2/
Title: Re: Row Totals for n-Columns
Post by: paramvir on August 31, 2020, 03:40:32 pm
you may add a property includeInSum: true to those columns and then use a formula to sum the columns.


Code: [Select]
                formulas: [
                  ['sum', function(rd){                 
                    var val = 0;
                    this.getColModel().forEach(function(column){
                      if(column.includeInSum){
                          val += rd[ column.dataIndx ] * 1;
                          }                     
                    })
                    return val;
                  }]
                ],


https://jsfiddle.net/eafr126d/
Title: Re: Row Totals for n-Columns
Post by: mikep on August 31, 2020, 04:39:52 pm
Thank you. Is there a way to apply that at the group level?
https://jsfiddle.net/qpu7fdLj/
Title: Re: Row Totals for n-Columns
Post by: paramvir on August 31, 2020, 09:10:58 pm
Formula doesn't work for group title rows.

However end result can be achieved in some cases ( such as yours ) by adding summary: {type: 'sum'} to last column also.

https://jsfiddle.net/stgbvnpr/
Title: Re: Row Totals for n-Columns
Post by: mikep on August 31, 2020, 09:19:08 pm
That worked. Thank You!