Search code examples
mysqlextjsstoreextjs4.2

Extjs Store shows zero records just after application refresh


As I invoke a function from controller that performs the following task,

var store= new Ext.getStore('MyStore'); //The store gets its data from mysql db
store.load(); 
console.log(store.getTotalCount());

shows the total count as zero for the 1st time after application refresh and shows the actual count i.e the actual number of rows in the store for subsequent invocation of the function.

I would really appreciate if someone could please guide me towards the resolution of the issue.


Solution

  • Since store.load() is asynchronous (I assume that you use remote proxy like ajax) and you call store.getTotalCount() immediately after you call store.load() first time you use it store is not loaded yet.

    You have to check totalCount withink store load callback, like this:

    var store= Ext.getStore('MyStore'); //The store gets its data from mysql db
    store.load({
        callback: function() {
            console.log(store.getTotalCount());
        }
    });