ParamQuery grid support forum

General Category => Bug Report => Topic started by: sdswuxi2017 on May 25, 2017, 02:18:34 pm

Title: calculateSummary
Post by: sdswuxi2017 on May 25, 2017, 02:18:34 pm
Hi,

I have a question  about calculateSummary() where I use multiplication or Division formula.
please check the attachment.

Title: Re: calculateSummary
Post by: paramvir on May 25, 2017, 05:47:14 pm
Just use

Code: [Select]
formula: function (ui) {
     var rd = ui.rowData;
     return rd.qty * rd.price;
}

in the amount column formula.
Title: Re: calculateSummary
Post by: sdswuxi2017 on May 26, 2017, 10:54:13 am
Hi Sir,

I used the code you mentioned above, but it was not exactly the result i want.
In your code, the calculated column value could be rd.qty * rd.price. It's correct. But in the Summarydata row, the value of this cell will be calculated with the same logic in above cells: sum(rd.qty) * sum(rd.price).  In my case, we cannot calculate list this.
Please see attached screenshot and you may get a better understand to what i actually asked. The formula marked in Red is the one pqgrid provides and the formula marked in Green will be the one i want to achieve.

Thanks a lot in advance.
Title: Re: calculateSummary
Post by: paramvir on May 28, 2017, 10:42:23 pm
I see, you are right. I'm able to reproduce the mentioned issue with the formula.

I'm moving it to bug report, thanks for reporting the issue.

Meanwhile you would need to calculate the product column manually ( instead of using the formula ) in calculateSummary() function.
Title: Re: calculateSummary
Post by: sdswuxi2017 on June 20, 2017, 09:02:15 am
Hi Sir,

Would you please advise if this bug will be fixed in next release? And when it would happen?

Thanks.
Title: Re: calculateSummary
Post by: paramvir on June 21, 2017, 12:10:31 am
I found that it works fine with some modifications in the example code.

Code: [Select]
  //calculate summary data.
  function calculateSummary() {
    var revenueTotal = 0,
      profitTotal = 0,
      productTotal = 0,
      data = this.option('dataModel.data'),
      len = data.length;

    data.forEach(function(row){
      revenueTotal += row.revenues;
      profitTotal += row.profits;
      productTotal += row.product;
    })

    var revenueAverage = (revenueTotal / len),
      profitAverage = (profitTotal / len),
      productAverage = (productTotal / len),
      totalData = {
        rank: "Total",
        company: "",
        revenues: revenueTotal,
        profits: profitTotal,
        product: productTotal,
        pq_rowcls: 'green',
        summaryRow: true
      },
      averageData = {
        rank: "Average",
        company: "",
        revenues: revenueAverage,
        profits: profitAverage,
        product: productAverage,
        pq_rowcls: 'yellow',
        summaryRow: true
      };

    this.option('summaryData', [totalData, averageData]);
  }

Code: [Select]
{ //formula field.
      title: "Expenditure = Revenues * Profits",
      dataType: "float",
      dataIndx: 'product',
      format: '$##,###.00',
      editable: false,
      formula: function(ui) {
        var rd = ui.rowData;
        if (rd.summaryRow) {
          return rd.product;
        } else {
          return rd.revenues * rd.profits;
        }
      }
    }

Code: [Select]
    //calculate summary upon these 2 events.
    dataReady: calculateSummary,
    change: calculateSummary,   

http://jsfiddle.net/dhnygcmf/2/

Hope it helps.
Title: Re: calculateSummary
Post by: sdswuxi2017 on June 23, 2017, 01:28:23 pm
 The issue has been resolved,thank you. :)