ParamQuery grid support forum

General Category => Help for ParamQuery Pro => Topic started by: nuno.nogueira on February 11, 2014, 06:33:47 pm

Title: Totals for columns
Post by: nuno.nogueira on February 11, 2014, 06:33:47 pm
Is it possible to calculate a total for certain columns without using grouping?

I have in colModel:

Code: [Select]
summary:{
            type:["sum"],
            title: ["<b style='font-weight:bold;'>Total:</b> {0}"]}
            },

Which doesn't show any total.

If I group the 3 columns for which I want totals, it does calculate the totals but it looks really weird since these are values columns (that shouldn't be grouped).
Title: Re: Totals for columns
Post by: paramvir on February 12, 2014, 10:08:23 am
If you need totals without using grouping, then this one is for you.

http://paramquery.com/pro/demos/summary


======================

It's not right to group by the same column for which you want summary. Please have a re-look at the grouping demo.




Title: Re: Totals for columns
Post by: nuno.nogueira on February 12, 2014, 05:39:14 pm
My data is remote, therefore, I need to count the total number of rows in the table to create the loop.

Code: [Select]
var numRegistos=$('#tabela').pqGrid("option","totalRecords");
Is returning "null", therefore, no totals.

How can I count the total number of rows?
Title: Re: Totals for columns
Post by: paramvir on February 12, 2014, 07:51:31 pm
Total number of rows available on client side is dataModel.data.length
Title: Re: Totals for columns
Post by: nuno.nogueira on February 12, 2014, 09:08:31 pm
Ok, so this returns the number of rows:

Code: [Select]
$('#tabela').pqGrid("option","dataModel.data.length");
So how do I sum the totals for a given row??

Using a loop seems ok but what kind of method/option shall I use?

This doesn't work:

Code: [Select]
for (var i = 0; i < numRegistos; i++) {
    orcamentoTotal += parseFloat($('#tabela').pqGrid("getCell",{rowIndx:i, dataIndx:"orcamento"}));
};

I read the API and searched for examples but I couldn't find anything.
Title: Re: Totals for columns
Post by: paramvir on February 12, 2014, 09:24:07 pm
dataModel.data is an array of rows.

Code: [Select]
var data = $grid.pqGrid("option", "dataModel.data");

var sum = 0;
for(var i=0, len=data.length; i<len; i++){
    var rowData = data[i];
    sum += parseFloat( rowData["orcamento"] );
}
Title: Re: Totals for columns
Post by: nuno.nogueira on February 12, 2014, 09:28:20 pm
Ok, that's exaclty what I was looking for!

Thanks!
 :D