PDA

View Full Version : Summary Grid - Calc a Summary Column Using Other Values in Summary Row



evay
21 Aug 2014, 7:57 AM
I have a summary grid that sums the values of two basic number columns but I want the next column in the summary row to show a calculation containing the values of the sums in the first two columns. Specifically, I want a Percent Change summary that reflects the change between the sums of the first two columns.

Here's a snippet of my grid with the three columns I'm talking about:


xtype: 'numbercolumn',
dataIndex: 'lastYearWages',
text: 'LY Reg Wages',
renderer: function(val, meta) {
return '$' + Ext.util.Format.number(val, '0,000');
},
summaryRenderer: function(val, params, data) {
return '$' + Ext.util.Format.number(val, '0,000');
},
summaryType: 'sum'
}, {
xtype: 'numbercolumn',
dataIndex: 'thisYearWages',
text: 'TY Reg Wages',
renderer: function(val, meta) {
return '$' + Ext.util.Format.number(val, '0,000');
},
summaryRenderer: function(val, params, data) {
return '$' + Ext.util.Format.number(val, '0,000');
},
summaryType: 'sum'
}, {
xtype: 'numbercolumn',
dataIndex: 'pctChg',
text: '%Chg',
renderer: function(val, meta) {
meta.style = val < 0 ? "color: #FF0000;" : "color: #000000;";
return Ext.util.Format.number(val, '0,000.00');
},
summaryRenderer: function(val, params, data) {
???
},
summaryType: ??
.
.
.

So really what I want is the third column to display the result of: (SumOfThisYearWages - SumOfLastYearWages) / SumOfLastYearWages

Can this be done? If so, how can I achieve it? (I'm using Ext JS 4.1.1)

Thanks, in advance, for any feedback!

Scott-1
21 Aug 2014, 8:35 AM
Your summary row contains access to the entire store. So you can sum up the store anyway you want. It does not need to be dependent on the column of information it can really be about anything.

summaryRenderer: function(value, summaryData, dataIndex) {
var paymentTotal = this.grid.getStore().sum('paymentTotal');
var orderTotal = this.grid.getStore().sum('orderTotal');
var percentage = (( paymentTotal / orderTotal ) * 100).toFixed(2);
return percentage.toString() + '%';
}

evay
21 Aug 2014, 10:47 AM
Exactly what I was looking for. Thank you!