View Full Version : Get Grid Column Total in textbox outside grid

22 May 2013, 6:22 PM

I have a grid with two columns as under:
I am using the grid summary feature to get the total of the Qty Allocated column. But I want to hide the summary row when the app runs and display the same total in a textbox outside the grid but on the same form.

How do I achieve that.

Any help will be appreciated.

22 May 2013, 11:03 PM
I havent used the summary feature so dont know how it exactly works but one possible solution is to use a normal grid (without summary because you dont want to show it anyway) and then just loop over the records in the store and calculate the total yourself:

// For example you want to calculate the total for the field "field1"
var total = 0;
var allRecords = store.getRange();
for(var i=0; i<allRecords.length; i++)
total = total + allRecords[i].get('field1');

23 May 2013, 1:25 PM
Thanks fo ryour reply.

I had that idea, but I was wondering if there is anyway to get the value using the summary feature. Because that makes it so much more easier.

But anyways I tried your suggestion such as this: I an using this code on the special key event of the grid cell editing textbox. But it always comes back as 0. What do you reckon.

var grid = Ext.getCmp('allocateTitlesGrid');
var store = grid.getStore();
console.log('Reached Store');
var total = 0;
var allRecords = store.getRange();
for(var i=0; i<allRecords.length; i++){
total = total + allRecords[i].get('QuantityAllocated');
var setTextbox = Ext.getCmp('currentAllocationTextbox');

23 May 2013, 10:39 PM
print the value of the record's field in the loop and see if you get all values. also, is that field a string? you might need to use parseInt...