ParamQuery grid support forum
General Category => Bug Report => Topic started 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.
-
Just use
formula: function (ui) {
var rd = ui.rowData;
return rd.qty * rd.price;
}
in the amount column formula.
-
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.
-
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.
-
Hi Sir,
Would you please advise if this bug will be fixed in next release? And when it would happen?
Thanks.
-
I found that it works fine with some modifications in the example code.
//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]);
}
{ //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;
}
}
}
//calculate summary upon these 2 events.
dataReady: calculateSummary,
change: calculateSummary,
http://jsfiddle.net/dhnygcmf/2/
Hope it helps.
-
The issue has been resolved,thank you. :)