PDA

View Full Version : How to get correct count of the Grids store?



AtulDawkhare
7 Dec 2011, 5:15 AM
Hi There,

I am able to get the store in the Grids dockItem. Here is the code
This dockedItems is to Gird.panel



dockedItems: [{
xtype: 'toolbar',

items :[
'->',
{
xtype: 'tbtext',
text : 'No Records to Display',
scope : this,
listeners:{
afterrender: function()
{ var me = this;
store = Ext.data.StoreManager.lookup('myStore');
store.load();
alert(store )
var count = store.getCount();
var text = ""
alert(count)
}
}
}
],
dock: 'bottom'

}],


my store is



var store2 = Ext.create('Ext.data.Store', {
pageSize: 5,
storeId: 'myStore',
model: 'ForumThread2',


But the store is not showing correct records from store.

Please guide me. I want to know what is wrong here? I want correct count in the "count" variable.

vadimv
7 Dec 2011, 5:25 AM
store load is an asynchronous process....

AtulDawkhare
7 Dec 2011, 5:39 AM
So do you mean that, we can not get the exact count to the toolbar ?

Please suggest , what can be done if this is not possible.

vadimv
7 Dec 2011, 5:59 AM
I mean, do what ever you want with the store data only after data is loaded, in a callback:



store.load({
scope :this,
callback:function(records, operation, success){
//the operation (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Operation) object contains all of the details of the load operation console.log(records);
}});

consult http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-load

AtulDawkhare
7 Dec 2011, 6:39 AM
Thank you So much.. It is working now..

vadimv
7 Dec 2011, 6:46 AM
I would suggest you to read about asynchronous and synchronous requests.
p.s don't forget to mark answered.