PDA

View Full Version : ComboBox Set Initial Value



keithcortis
9 Sep 2009, 1:00 AM
Hey guys,

I am still new on EXTJS and what I am trying to do is set the initial value of a combobox (or on button click - but that does not matter since it is a matter of events), where I am using a JsonStore to retrieve data from a database which data consists of country_code and country_name. Thus I would like that on page load if i give my store/combobox the country_code it will automatically issue a request to the server inorder to find the name of that particular country..

Can this be done by passing a query string (parameter ) in the url for example:
countries.php?country_code=AN -> this would return Andorra and thus Andorra would be selected in the ComboBox...

Thanks a lot and hope i find a solution since i need it for a lot of projects

Lloyd K
9 Sep 2009, 1:31 AM
Really you'd want something like Ext.direct or an Ajax request to do this and handle it all on the php side and not via a store.

However if the store has fully loaded then it's just a matter of looping the records and finding the one you want.

keithcortis
9 Sep 2009, 1:58 AM
But my issue is that the request for the items to be displayed in the combobox is done via the server but I would like the possibility of setting the value of the combobox by just specifying the country_code for example and it will return the country_name... I have already managed to do this by loading the store and then on button click i set the value with the country_code.. but i am seeing the possibility of a request being made for every combobox depending on the country_code that it is given..

what do you think?

keithcortis
9 Sep 2009, 3:05 AM
To make my query simpler and more understandable:

If i type "Mal" in a combobox the combo queries "countries.php?country_name=Mal" where the country_code "MT" and country_name "Malta" should be the response.
What i need is the same combo setting the value "MT", where the combo then queries "countries.php?country_code=MT" where "MT" and "Malta" are the response.

any ideas how this can be set?

Rammynampati
9 Sep 2009, 3:48 AM
Your explanation making more confusion. You want to set some values to the combo box before you load data from DB? If that true then get that item using Ext.Cmp("id of the combo") and setValue to that.

keithcortis
9 Sep 2009, 6:58 AM
So, I have a combo with a remote store. When I type something, e.g. "Malt", I get correctly back "MT" and "Malta" and Malta is shown as expected. What I need is that I dynamically "set" the combo to MT and it should do the same query so that "Malta" will be displayed (and not MT). How can I get this done?
thanks

Lloyd K
10 Sep 2009, 1:03 AM
Ahhh I think your problem is because the store isn't fully loaded when you come to set the value, it's a common issue people have.

You can solve it a number of ways, the way I do it is to turn off autoLoad on the store and do this after I've created the combo:



var comboLoad = function(store,records,options) {
store.un("load",comboLoad,this);
combo.setValue("MT");
};

combo.store.on("load",comboLoad,this);
combo.store.reload();

keithcortis
10 Sep 2009, 1:48 AM
thanks for your reply - i tried it out but it still does not work - the problem is that when i preload the store - not all of the countries are being loaded but only the first five... and i would not like to load all the countries cause it would signify much more work load on the server? or only by preloading the records of the store this can work?

thanks

Condor
10 Sep 2009, 2:13 AM
You could try this solution (http://www.extjs.com/forum/showthread.php?p=385027#post385027).

keithcortis
10 Sep 2009, 3:27 AM
thanks for all the answers.. i have nearly solved it since what i only need is that if i get a value from the server being for example MT - how can i retrieve the data that i get from the server (the response) so that i can pass it as a query in the load of the jsonstore... i jsut would like to know how i can retrieve the data that i get from the server.. thanks