Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: return total rows/records in json store

I have a json store that returns values in json format. Now I need to get the number of rows/records in the json string but when I use store.getCount() function it returns 0, but the combobox is populated with rows, and when I use store.length I get undefined, probably because its not an array anymore, its returning from store, which is calling php script. Anyways, whats the best approach for this problem?

like image 701
Grigor Avatar asked Jul 29 '11 19:07

Grigor


2 Answers

Try this out:

var myStore = Ext.extend(Ext.data.JsonStore, {
  ... config...,
  count : 0,
  listeners : {
    load : function(){
      this.count = this.getCount();
  }
}

Ext.reg('myStore', myStore);

and then use inside panels:

items : [{
 xtype : 'myStore',
 id : 'myStoreId'
}]

Whenever you need to get the count then you can simply do this:

Ext.getCmp('myStoreId').count
like image 194
Varun Achar Avatar answered Sep 25 '22 04:09

Varun Achar


Your Json response from server, can be something like this...

{
    "total": 9999,
    "success": true,
    "users": [
        {
            "id": 1,
            "name": "Foo",
            "email": "[email protected]"
        }
    ]
}

Then you can use reader: { type : 'json', root : 'users', totalProperty : 'total', successProperty: 'success' } in your store object.

like image 39
toopay Avatar answered Sep 22 '22 04:09

toopay