Author Topic: Bug in pivot demo  (Read 493 times)

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Bug in pivot demo
« on: July 04, 2023, 11:49:56 am »
When  the pivot demo's foumula is changed to  do division(  line 89,  code as below ),  the "sum(total)" column's value is wrong.
Is there any solution for it?

formulas: [['total', function(rd){
    var total = rd.gold /rd.silver;
    return isNaN(total) || !isFinite(total)? "": total;
}]],

In the following pic, in the 1st line, the result should be 2.1, but it becomes 8.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Bug in pivot demo
« Reply #1 on: July 04, 2023, 02:15:36 pm »
formulas are applied to plain or non - pivoted data.

Aggregate values in pivot view are determined by aggregate functions used in that field, so in your case SUM function is used to calculate the Total value.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Re: Bug in pivot demo
« Reply #2 on: July 04, 2023, 02:51:23 pm »
Dear Paramvir,
Do you mean that this issue couldn't be fixed in pqGrid?
You know that this is a very useful function of the pivottable in excel.
I'm tring to debug your code, would you like to inform me where to change the code to fix it?
Or may be after pivot table loaded, let pqgrid calculate fumula for all related columns?
« Last Edit: July 04, 2023, 02:54:15 pm by hyh888 »

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Re: Bug in pivot demo
« Reply #3 on: July 04, 2023, 06:44:09 pm »
After pivot table loaded, let pqgrid calculate fumula for all related columns。By this way(only adjust the order of js function excecuted), maybe the efficency of qpGrid can be improved, and its function get more powerful.
I'm tring to find the whereness to change it, but it's really difficult for the code has been compressed.
« Last Edit: July 04, 2023, 07:04:27 pm by hyh888 »

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Re: Bug in pivot demo
« Reply #4 on: July 04, 2023, 08:06:32 pm »
But for average and count function, you have to keep the original execution order.  Maybe pqGrid should use UDF to mark the division or multipliation formula, then after data loaded in interface to calculate the formula for UDF fields.

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6255
    • View Profile
Re: Bug in pivot demo
« Reply #5 on: July 05, 2023, 12:12:12 pm »
Dear hyh888

You need to use custom aggregate function rather than formula for your requirement.

Code: [Select]
pq.aggregate.my_custom = function(arr, col, rows, rd){
var di = col.dataIndx;
var val = rd[di.replace("total", "gold")] / rd[ di.replace("total", "silver") ];
return (isNaN( val ) || !isFinite( val ))? "": val;
}

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Re: Bug in pivot demo
« Reply #6 on: July 05, 2023, 04:02:40 pm »
million thanks, I will try it.

hyh888

  • Pro Enterprise
  • Full Member
  • *
  • Posts: 130
    • View Profile
Re: Bug in pivot demo
« Reply #7 on: July 06, 2023, 11:24:27 am »
Dear Paramvir,
It really works in my application. You're the best.
I hope you can make a demo in your website, and let more people know it.
It's  really a powerful function.