PDA

View Full Version : Use same store for all multiselect and combo boxes?



hadi78
30 Nov 2009, 5:44 AM
Hi,

Is there a way to use the same store for different multiselect boxes and combo boxes without that Ext JS makes one request for each box? Its just that i have many combo boxes and multiselect boxes having a list of countries with over 300 entries each. Because of that i only would like to make only one request to the server to get the list of countries and only use this for all boxes.

VinylFox
30 Nov 2009, 6:00 AM
Change the combobox's mode to 'local' and call the load method manually on your store.

hadi78
30 Nov 2009, 6:35 AM
Thx, i would really appreciate it if you could provide me with a simple example.

what if i for exmaple have this code:



.....
.....
layout: 'form',
items: [
{
xtype:'combo',
fieldLabel: country_of_identification,
name: 'victim_case[country_of_identification_attr]',
hiddenName: 'victim_case[country_of_identification_attr]',
displayField: 'label',
id: 'add-case-country-of-identification-'+vCase.id,
allowBlank:true,
typeAhead: true,
mode: 'local',
forceSelection: true,
selectOnFocus:true,
store: countries,
style: 'background-color: #FFF',
valueField: 'id' ,
triggerAction: 'all'
},
....
....
This is my store:


var countries = new Ext.data.Store({
reader: new Ext.data.JsonReader({
idProperty: 'id',
root: 'countries',
totalProperty: 'results',
fields: [
{ name: 'id', mapping: 'country.id' },
{ name: 'label', mapping: 'country.label' }
]
}),
proxy: new Ext.data.HttpProxy({
url: '/victims/countries',
method: 'GET'
}),
autoLoad: true, // turn on server-side sorting
sortInfo: {field: 'id', direction: 'ASC'}
});
i set mode to local. Need i also to remove the store config optionin my combobox? Next i need get the combo box component, gets his store and call load on it?

hadi78
30 Nov 2009, 6:59 AM
ok i think i figured it out. Should this also work on multiselect boxes? I have tried it and get a strange behaviour:
I have a combobox and a multiselect box on the same page. When i now select the combo box and type in on my keyboard to navigate through the list in the combobox then the list on my multiselect box changes too. I know the problem is that i use the same store. How can i fix this?

VinylFox
30 Nov 2009, 2:47 PM
Then you will have to use multiple stores, one for each component, but that does not necessarily mean multiple requests for the same data.

You could use the first loaded store to populate the others, attach a handler to the 'load' event of that store, and use it to populate the data in the other stores by calling loadData on them.

ie:

your_main_store.on('load', function(s){
your_other_store.loadData(s.reader.jsonData);
your_other_other_store.loadData(s.reader.jsonData);
})

Haven't tested this, just an idea.