ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: hyh888 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.
-
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.
-
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?
-
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.
-
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.
-
Dear hyh888
You need to use custom aggregate function rather than formula for your requirement.
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;
}
-
million thanks, I will try it.
-
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.