PDA

View Full Version : how to get number objects in store?



kramal
25 Feb 2013, 10:39 PM
Hi, people! Can you help me in follow problem. I want to create panel with some number of buttons where number of buttons is defined as number of rows in store:

Ext.onReady(function(){
Ext.define('User', {
extend: 'Ext.data.Model',
fields: ['text']
});

var myStore = Ext.create('Ext.data.Store', {
model:'User',
getc:function(){
this.reload();
return this.getCount();

},
listeners:{
load : function(){
this.count = this.getCount();
alert(this.count);
}
},

proxy: {
type: 'ajax',
url: 'gg.json',
reader: {
type: 'json',
}
},
autoLoad:true
});


var panel=Ext.define('Panel',{
extend: "Ext.panel.Panel" ,
initComponent:function(){
this.title='panel';

this.width=300;
this.height=300;
this.renderTo=Ext.getBody();

var arr=[];
var ind = myStore.getc();
alert(ind+'oi');
for(var i=0;i<ind;i++){
arr={xtype:'button',text:myStore.getAt(i)}// [I]here is cretaed buttons
};
this.items=arr;
this.callParent(arguments);
}
});
Ext.create('Panel');

});

girish.arjunagi
26 Feb 2013, 4:09 AM
store.getCount() would give you number of model objects in it.

kramal
26 Feb 2013, 9:55 PM
Yes, but this method returns zero.

girish.arjunagi
26 Feb 2013, 10:18 PM
reload operation you are calling on the store is an asynchronous call. You should get the count only after the success or callback of the load operation. Please try the below code.
getc : function() {
this.reload({
callback : function(records, operation, success) {
var length = records.length;
}
});
},

var length will have the exact count.