PDA

View Full Version : Combo box Store is loading twice



dev_java
24 Aug 2011, 4:26 AM
Hi,

In my layout, i have a combo box which will be loaded on click of some button. I am using setValue() method to set first value of the store to combo box. It works fine, but 'autoLoad:true' is not working.
After setting the value, when i try to select the drop down arrow of the combo , the store is loading again. This happens only for the first time.

27671

Can any one tell how to restrict the combo load on select of drop down arrow?

Please find my piece of code



//Store Model
Ext.define('grpStoreModel',{
extend: 'Ext.data.Model',
fields: [
'group',
'groupValue'
]
});

//Store
function getGroupStore()
{
return Ext.create('Ext.data.Store', {
id:'grpStore',
model: 'grpStoreModel',
autoLoad:false,
proxy: {
type: 'ajax',
url:'../datas/getGroupDetails.htm',
extraParams:{grpn:grpVal},
reader: {
type : 'json',
totalProperty:'grpListSize',
root:'grpList',
successProperty: 'success'
}
},
listeners:
{
'load':{
fn: function(store, records, options) {
if(store.getCount()>0){
Ext.getCmp('group_Combo').setValue(store.getAt(0).data.group);
}

}
}
}

});
}

// Group Combo code

{
xtype: 'combo',
id : 'group_Combo',
width:225,
fieldLabel:'Group',
store: getGroupStore(),
valueField : 'group',
displayField : 'groupValue',
listeners:{
select : function( combo, record, index ) {

}
}
}


// Store load is done on button click

Ext.getCmp('group_Combo').getStore().load({
params:{
grpn:grpVal
}
});




Thanks in advance
dev_java

FoxMulder900
24 Aug 2011, 5:09 AM
In your combo box try adding:

queryMode: 'local'
Since you are loading the store yourself I think this will keep the combo from trying to load the store again on the first click.

ValterBorges
24 Aug 2011, 10:57 AM
Take a look at the lastQuery property, if you look under my posts there was a post about this.

Set it to null to reload first time.
Set it to '' to prevent reloading after store is already loaded.

If you reassign a preloaded store to the combo programmatically you also want to set this because it will reset.

dev_java
24 Aug 2011, 9:39 PM
In your combo box try adding:

queryMode: 'local'
Since you are loading the store yourself I think this will keep the combo from trying to load the store again on the first click.

Hi,

Thanks for your reply.
I added queryMode: 'local' to combobox and it worked very fine.

Danv
23 Jan 2012, 1:59 PM
Hi,

Thanks for your reply.
I added queryMode: 'local' to combobox and it worked very fine.

+1

It fixed my issue also, thanks!

Never thought I would find the exact same issue on the forum :)

jay@moduscreate.com
23 Jan 2012, 5:18 PM
This is one of those "tips" that i stress at the Ext JS bootcamps that we do :)

sundae
15 May 2012, 1:27 AM
I had do that by adding queryMode:'local',
but still not working.. pls help

sundae
15 May 2012, 2:02 AM
It's filnally work after adding
queryMode:'local',
and

Ext.override(Ext.LoadMask, {
onHide: function() { this.callParent(); }
});

that code from thread http://www.sencha.com/forum/showthread.php?156908-combobox-queryMode-local-still-shows-loading

kanchan@rhytha.co.in
21 Aug 2012, 11:50 PM
I tried
queryMode: 'local'

This works for me.

garrek99
15 Jun 2013, 8:39 PM
Take a look at the lastQuery property, if you look under my posts there was a post about this.

Set it to null to reload first time.
Set it to '' to prevent reloading after store is already loaded.

If you reassign a preloaded store to the combo programmatically you also want to set this because it will reset.

If you use queryMode: 'local' the combobox will filter out data in the store that doesn't match what the user typed. I know in most cases this is perfect but in some cases where the search logic is done sever side and the store contains other data that the user may wish to pick from the drop down this method won't work.
(In my case I return names that match the search term inside either the last name or the first name. queryMode.local would filter out all the names that matched the first name but not the last since the last name displays before the first. ie: Smith, Bob and search term was "bob".)

But, in line with ValterBorges' response I would suggest setting lastQuery to the value you just queried manually before the store has loaded the results. Setting it to '' as suggested didn't work.





listeners: {
change: function (cmp, newValue, oldValue, eOpts) {
//Initiate search only after 3 characters are available
if (newValue && newValue.length > 2) {
cmp.lastQuery = newValue;
cmp.getStore().load({
params: { name: newValue },
callback: function (records, operation, success) {
...
}
});.
}
}
}