PDA

View Full Version : Count store records with condition



KostasP
31 Jul 2012, 11:09 AM
Is there a way to conitionally count the records of a store, ie. those records that have a specific value in a given field?

scottmartin
31 Jul 2012, 11:19 AM
You could use:



store.each(function(record) {
// condition
});


Scott.

KostasP
31 Jul 2012, 11:37 AM
thanks. that's what i did.


var evts=0; var rprs=0;
store.each(function(record) {
var rep = record.get('EvtRepaired');
if(rep==0 || !rep || rep=="") {
if(record.get('EvtRprID')) rprs+=1;
else evts+=1;
}
});

by the way, for anyone who finds this thread if u are using a remote api store put the code in a store load callback cause the onLaunch function of the controller is not late enough for the store to be ready and loaded.

bikrems
13 Mar 2013, 6:08 PM
Hi KostasP

I have one doubt...Where did you put the code i.e in store or somewhere else???

Thanx and waiting for your reply

quentinuys
29 Mar 2017, 3:27 AM
Hi KostasP

I have one doubt...Where did you put the code i.e in store or somewhe re else???

Thanx and waiting for your reply

You can use this anywhere you have access to Ext.
Define the store using
store = Ext.getStore('yourstoreid')