PDA

View Full Version : Combobox not showing data from store



citron
11 Oct 2012, 1:46 PM
Hello all,

I have a problem with loading data into combobox.

My code:



Ext.define('noe.invoice.QuickFilter', {
extend: 'Ext.toolbar.Toolbar',
alias: 'widget.noeQuickFilterInvoice',

requires: [
],

items: [
{
xtype: 'component',
html: 'Filtrace',
margin: '0 10 0 10'
},
{
xtype: 'combobox',
emptyText: "Vybrat",
width: 300,
displayField: 'name',
valueField: 'code',
store: Ext.data.StoreManager.lookup('staffStore'),
queryMode: 'remote',
triggerAction: 'all'
},
{
xtype: 'button',
text: 'Zrusit',
itemId: 'cancelQuickFilter',
margin: '0 0 0 5'
}
],

initComponent: function() {
Ext.create('Ext.data.Store', {
storeId: 'staffStore',
autoLoad: true,
fields: ['code', 'name'],
proxy: {
type: 'jsonp',
url : noe.main.settings.api_url+'?action=getSalesStaff',
reader: {
type: 'json'
}
}

});

this.callParent(arguments);
}
});


The proxy from store return this data:




Ext.data.JsonP.callback2([{"code": "cc1", "name": "Country 1"}, {"code": "cc2", "name": "Country 2"}]);

But the combobox is empty.

What could be wrong?

mitchellsimoens
15 Oct 2012, 8:32 AM
That's because the store doesn't exist when the lookup happens. You need to do this:


Ext.define('noe.invoice.QuickFilter', {
extend : 'Ext.toolbar.Toolbar',
alias : 'widget.noeQuickFilterInvoice',

initComponent : function () {
this.items = [
{
xtype : 'component',
html : 'Filtrace',
margin : '0 10 0 10'
},
{
xtype : 'combobox',
emptyText : "Vybrat",
width : 300,
displayField : 'name',
valueField : 'code',
queryMode : 'remote',
triggerAction : 'all',
store : Ext.create('Ext.data.Store', {
autoLoad : true,
fields : ['code', 'name'],
proxy : {
type : 'jsonp',
url : noe.main.settings.api_url + '?action=getSalesStaff',
reader : {
type : 'json'
}
}
})
},
{
xtype : 'button',
text : 'Zrusit',
itemId : 'cancelQuickFilter',
margin : '0 0 0 5'
}
];

this.callParent();
}
});