View Full Version : [Solved] Load a ComboBox, Load a Datastore and set the combobox value with ds data

11 May 2009, 12:30 AM

My title isn't very explicit, what I'm looking for is the best way to load a datastore, load a combobox, and when both are loaded, set the combobox value with a datastore data.

I think it's something that people should do everyday here, and my way works, but has a little bug.

What I do is like that :

- I create a function for the datastore event "load"
- In that function, I put a combobox datastore listener on the "load" event too
- In the combobox function, I set the value with the datastore value (I thought both ds would be loaded here)
- I load the combobox in the datastore on load event

Looks like this :

var datastore = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url: some_url }),
reader: new Ext.data.JsonReader({}, [fields_here]),
remoteSort: true

datastore.on('load', function(store){
var data = datastore.getAt(0).data;

cboDs.on('load', function(){

When I'm opening tabs with this code, some times everything works, but other times I juste got the Id's in my combo box values because it hasn't been loaded.

If someone knows a way to do that better, I would be glad :)

Thank you,

11 May 2009, 1:32 AM
There are several solutions:
1. Delay the setValue until the store is loaded (example here (http://www.extjs.com/forum/showthread.php?p=285246#post285246)).
2. Set both the value and the display text at the same time (example here (https://extjs.com/forum/showthread.php?p=141064#post141064)).
3. Load the data for both stores in one request (preferred method, because it only takes one request).

11 May 2009, 2:00 AM
Thank you for your answer.

The third choice may be the best, but I think it's not for me since I could have like 10 combobox to load in my datastore.

I'll try one of the 2 above :)