magut
magut

Reputation: 41

How to calculate total of one field in the store

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.

Upvotes: 4

Views: 6205

Answers (2)

mfruizs
mfruizs

Reputation: 770

Use the store summary function:

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

sencha api: sum store

Upvotes: 3

Hadas
Hadas

Reputation: 10374

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'); });
    }
});

Upvotes: 5

Related Questions