View Full Version : Extjs 4 grid summary for textfield

22 Feb 2013, 10:12 AM
I have a grid with editable textfields(Ext.form.field.Number) and a summary row(Ext.grid.feature.Summary)

If I set the summaryType to 'sum', it will append the sum, ie)
row 1 123
row 2 123
summary 123123

Thus I am using the custom summaryType function which passes in the entire list of records, with each column. So to update a field, I am directly referencing it(see FIELD_NAME).
function summaryRoundAndAddCommas(records)
var sum = 0;
for(i=0; i<records.length; i++)
sum = sum + parseInt(records[i].data.FIELD_NAME);
return sum;

However I have a couple of columns that are textfields and require a summary column. I don't want to have x functions that are identical other than for the field they are summing.

Is there any way to access the column for which a summary row is being calculated to reuse this function?

Or am I doing this the difficult way? ie) can I somehow override Ext.grid.feature.Summary to sum strings?

22 Feb 2013, 10:35 AM
Can you set the type to int for the summary field, even if the data is string .. and it should work

Ext.define('TestResult', {
extend: 'Ext.data.Model',
fields: [
{ name: 'month1', type: 'int' },
{ name: 'month2', type: 'int' }, // field has string data
name: 'total', type: 'int',
convert: function(val,row) {
return row.data.month1 + row.data.month2;

store: {
model: 'TestResult',
data: [{
student: 'Row 1',
month1: 100,
month2: '50' // string data
student: 'Row 2',
month1: 200,
month2: '100'
student: 'Row 3',
month1: 300,
month2: '150'


22 Feb 2013, 2:43 PM
That worked perfectly thanks.

Seemed like it should be easier.