ExtJS: returns summary lines / records in json store

I have a json repository that returns values ​​in json format. Now I need to get the number of rows / records in the json string, but when I use the function store.getCount(), it returns 0, but the lines are filled in the combo box, and when I use store.length, I get undefined, perhaps because its not an array anymore, its return from the repository that calls the PHP script. Anyway, what's the best approach for this problem?

+5
source share
4 answers

Try the following:

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

Ext.reg('myStore', myStore);

and then use the inner panels:

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

Whenever you need to get an invoice, you can simply do this:

Ext.getCmp('myStoreId').count
+4

Json , - ...

{
    "total": 9999,
    "success": true,
    "users": [
        {
            "id": 1,
            "name": "Foo",
            "email": "foo@bar.com"
        }
    ]
}

reader: { type : 'json', root : 'users', totalProperty : 'total', successProperty: 'success' } .

+3

Starting with docs , if your data source is provided, you can call getTotalCountto get the size of the data set.

+3
source

If you use ajax proxy for storage, smth like

proxy : {
   type : 'ajax',
   url : 'YOUR URL',
   reader : {
       type : 'json',
       root : 'NAME OF YOUR ROOT ELEMENT',
       totalProperty : 'NAME OF YOUR TOTAL PROPERTY' // requiered for paging
   }
}

and then load your store as store.load (); An asynchronous Ajax request will be sent, so you should check the counter in the callback like this

store.load({
  callback : function(records, operation, success) {
       console.log(this.getCount());         // count considering paging
       console.log(this.getTotalCount());    // total size
         // or even 
       console.log(records.length);          // number of returned records = getCount()
  }
});
+3
source

All Articles