Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate total of one field in the store

Tags:

grid

extjs

extjs4

I have a grid within a form as in the attached image. When the the customer name is changed, then the grid store is loaded with records corresponding to the customer. I want the balance textfield to be populated with the sum of Amount due column.

The image is here.

like image 761
magut Avatar asked Feb 20 '23 08:02

magut


2 Answers

Use like this:

store.load({
    scope   : this,
    callback: function(records, operation, success) {
        //here the store has been loaded so you can use what functions you like.
        //This code sum numbers in certain column
        sum = 0; 
        store.each(function (rec) { sum += rec.get('NameColumn'); });
    }
});
like image 101
Hadas Avatar answered Feb 27 '23 08:02

Hadas


Use the store summary function:

var sum = grid.getStore().sum('NameColumn');

sencha api: sum store

like image 20
mfruizs Avatar answered Feb 27 '23 07:02

mfruizs