ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: nuno.nogueira on March 11, 2014, 05:43:02 pm
-
I'm using 'summary' to calculate subtotals as per your demo.
It seems, however, that when one of the values is zero or a calculated column, the subtotal isn't calculted. See Yellow marks in the attachment.
Also, I tried to add a different style to the group rows in my CSS, like:
.pq-group-row {
background-color: red !important;
}
As in the red rectangles of the attachment.
Thanks in advance for your support! :-\
-
1)
zeros are not a problem. There might be nulls in your data. Either remove the nulls (replace with 0) or implement a callback function for summary
http://paramquery.com/pro/api#option-column-summary
2)
calculated column : if it's a computed column in the view only (using render callback) then summary of that column won't work. You have to use actual field (dataIndx) in the data to make summary work. When you load data you can calculate the value in the computed field.
-
Ok, I've got the idea.
NULLS in the database are the problem...
Thanks!
-
Subtotals are working fine now!
Just one thing: I'm in Europe, and I need to format the numbers with comma for decimal separator, period for thousands separator and to use the Euro sign.
I have a function formatNumber that takes a number as an argument, to do just that.
But how do I pass the total to the summary. This is what I tried without luck:
summary: {
type: ["sum"],
title: ["<b style='font-weight:bold;'>Total :</b> formatNumber({0}, 2, ',', '.')"]
}
-
you can implement callback function
summary: {
type: function (arr){
//calculate sum of the elements in the arr.
//use formatNumber function
//and return value
},
title: [ "<b style='font-weight:bold;'>Total :</b> {0}" ]
-
I tried this but it doesn't work, what's wrong? :-\
summary: {
type: function(arr){
calculo=eval(arr.join("+"));
calculo=formatNumber(calculo,2,',','.');
return calculo;
},
title: ["<b style='font-weight:bold;'>Total :</b> {0}"]
}
-
What's the output.
-
Just empty cells.
-
put a debugger or alert statement in your type callback and see what each line of your code is doing.
-
It seems the function isn't even being called, since nothing is outputed to the console/alert:
summary: {
type: function (arr) {
calculo = eval(arr.join("+"));console.log("1 "+calculo);
calculo = formatNumber(calculo, 2, ',', '.');console.log("2 "+calculo);
return "calculo";console.log("3 "+calculo);
},
title: ["<b style='font-weight:bold;'>Total :</b> {0}"]
}
-
Correction from the API reference : http://paramquery.com/pro/api#option-column-summary
type is an array, it should be this:
type: [function (arr) {
calculo = eval(arr.join("+"));console.log("1 "+calculo);
calculo = formatNumber(calculo, 2, ',', '.');console.log("2 "+calculo);
return "calculo";console.log("3 "+calculo);
}]
-
Done. One less to worry about!
Thanks!