ParamQuery grid support forum
General Category => Help for ParamQuery Pro => Topic started by: TeeJT on July 10, 2018, 09:23:05 am
-
I need to have a group summary that is not an aggregate function (which is based on data in that column) but a formula based on data in other columns e.g. val = rd.Freight / rd.Deposit
How can I acheive this functionality?
I am using ParamQuery Pro 3.4
-
Using this discussion on formula for Grand Summary, I was able to do it from Grand Summary at the bottom of the grid. However I need it for the Group Summary too.
https://paramquery.com/forum/index.php?topic=2122.msg8407
-
Summary can be applied the same way to formula column as applied to normal column.
{
dataIndx: 'product',
formula: function(ui) {
return ui.rowData.Freight * 3;
},
summary: {
type: 'sum'
}
},
-
What I need in the summary is not a sum but a formula involving the sum of other columns e.g. sum(ui.rowData.Freight) / sum(ui.rowData.Deposit)
-
In that case column.render can be used.
{
dataIndx: 'product',
render: function(ui){
var rd = ui.rowData;
if( rd.pq_gsummary )
return rd.Freight / rd.Deposit
}
},
where Freight and Deposit columns have sum summary defined on them.
-
I have added a column to your demo at https://paramquery.com/pro/demos33/export
I added a column below but the result is empty because I did not define summary for that column. The summary function kicks in for the summary row and overwrites whatever was rendered. If summary is empty list then that cell is empty. If it is a sum, then it will be sum of the column.
{
title: "Product",
width: 120,
dataIndx: 'Product',
format: "##,###.00",
dataType: "float",
render: function(ui){
var rd = ui.rowData;
if( rd.pq_gsummary )
return rd.Freight * 2;
}
},
-
In that demo, summary is displayed in title rows, please try the below changes in column.render.
render: function(ui){
var rd = ui.rowData;
if( rd.pq_gsummary || rd.pq_gtitle)
return pq.formatNumber(rd.Freight * 2, ui.column.format);
}
-
Thank you very much! This was exactly what I needed.