简体   繁体   中英

how to get total records with a previous filter in a Sencha Touch app?

Working with an application based in Sencha Touch I need to get total amount of a store but with a previous filter implemented.

I can do store.getCount() and to know the total records of a store, but How to know total records with a previous filter?

Here is an alternative solution :

var count = 0;

store.findBy(function(rec) {
    if (rec.get('myFilter')) {
        count++; // Only counting matching data
    }
});

console.log(count); // Total amount of filtered data

From : https://www.sencha.com/forum/showthread.php?174156-Store-count-by-criteria-without-filter

If the store is filtered getCount() will retrieve the amount of records based on your filter. If you filter on 'Billy', the getCount() will return only 2 if there are 2 'Billy's'.

From the docs:

Gets the number of records in store.

If using paging, this may not be the total size of the dataset. If the data object used by the Reader contains the dataset size, then the Ext.data.ProxyStore.getTotalCount function returns the dataset size. Note: see the Important note in Ext.data.ProxyStore.load.

When store is filtered, it's the number of records matching the filter.

If you want to get the total amount of records you can use getTotalCount() . This will count all records, no matter if it's filtered or not.

From the docs:

Returns the total number of Model instances that the Proxy indicates exist. This will usually differ from getCount when using paging - getCount returns the number of records loaded into the Store at the moment, getTotalCount returns the number of records that could be loaded into the Store if the Store contained all data

If you want to query over the store you can use queryBy . This will return a collection of records. You can then use getCount() over the collection.

var billies = store.queryBy(function(rec, id) {
    return rec.get('name') === 'billy';
});

billies.getCount();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM