PDA

View Full Version : Dynamic Update to ComboBox?



Robk
14 Jun 2008, 7:09 PM
Is it possible to dynamically update a ComboBox? I don't see any way to a bind a store and ComboBox together.

Your help is greatly appreciated!!
Rob

gslender
14 Jun 2008, 7:48 PM
ComboBox.setStore(ListStore<D> store) ???

Robk
14 Jun 2008, 8:19 PM
Thanks, tried it and it seems to reset the values for the combobox but the drop down list is not refreshed on the screen.

A little more information I'm sure will help. I have 2 ComboBoxs, A and B. Values in B are dependent on the selection made in A.

An example would be countries in comboBox A and comboBox B shows the cities in that country. Default setting could be A = US and B would have a list of US cities. The user then could select A=UK and B would dynamically update with a list of cities in the UK.

Ideas?

Thanks
Rob

gslender
14 Jun 2008, 8:30 PM
please post a code snippet showing what you have done and what is not working - that way I can help simply by correcting your code sample.

Make sure if compiles without any extra classess/files that I would't have...

Robk
14 Jun 2008, 10:09 PM
Figured it out.

on the combobox A listener I changed the store update from

comboB.setStore(UKcities)

to

comboB.getStore().removeAll();
comboB.getStore().add(UKcities)


thanks for the help.
Rob

myj
23 Jun 2008, 9:40 PM
Hm, when I tried this, it says getStore() and setStore() method doesn't exist.

I am actually struggling with this for quite a few hours now. I need to dynamically
reconfigure my combobox depending on the selection made in another part of the page.

I ended up removing and recreating the combobox on the fly every time. Even there,
I couldn't get the value to show up, even as it appears there are empty items in the
pull down list... Pretty buggy for a I can see. using Ext 2.0...

Is this only available in Ext 2.1 ?

Robk
25 Jun 2008, 2:34 AM
Myj,

I'm using Ext GWT v1.0 Beta 4.

Rob

goeritz
27 Aug 2008, 4:46 AM
Hi!

I'm having the same problem: I also have two comboboxes where the values in combobox B depent on the selection in combobox A.
For this I added a listener to combobox A where I'm getting the new values to display in combobox B via a RPC call. I already tested whether data is retrieved correctly - and it is. The store contains my data models. But the checkbox B doesn't notice, that the store's data has changed. So I searched the API documentation (and the help center) and saw, that I have to implement an own combobox binder, which extends the StoreBinder class, to listen to DataChanged events of a store.

Am I right so far?

When I try to do this I have to implement a few methods, i.e. update(ModelData model). And I really don't know how to get the combobox updated.

It would be very nice if anyone could give me a hint.
I'm using GXT 1.0.1, GWT 1.5.0-rc1 and Windows XP SP3.

Here is an extract of my current code:




proxySite = new RpcProxy<Object, List<SamSite>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<SamSite>> callback) {

service.getSamSites(callback); //models for combobox A (aka cbxSite)
}
};

loaderSite = new BaseListLoader<ListLoadConfig, ListLoadResult>(proxySite);

storeSite = new ListStore<SamSite>(loaderSite);
loaderSite.load(null);

TextToolItem item;

LabelField sLabel = new LabelField("Site:");
this.add(new AdapterToolItem(sLabel));

cbxSite = new ComboBox<SamSite>();
cbxSite.setDisplayField("name");
cbxSite.setValueField("siteCode");
cbxSite.setEmptyText("Select a site...");
cbxSite.setSelectOnFocus(true);
cbxSite.setStore(storeSite);
cbxSite.addListener(Events.Select, new Listener<BaseEvent>() {

public void handleEvent(BaseEvent be) {

loaderApp.load(cbxSite.getValue());
}
});

this.add(new AdapterToolItem(cbxSite));
this.add(new SeparatorToolItem());

proxyApp = new RpcProxy<SamSite, List<SamSystem>>() {
@Override
protected void load(SamSite loadConfig, AsyncCallback<List<SamSystem>> callback) {

service.getSamApplications(loadConfig, callback); //models for combobox B (aka cbxApp)
}
};

loaderApp = new BaseListLoader<SamSite, ListLoadResult>(proxyApp);

storeApps = new ListStore<SamSystem>(loaderApp);

loaderApp.load(null); //LoadConfig is null - service returns empty List

LabelField aLabel = new LabelField("Application:");
this.add(new AdapterToolItem(aLabel));

cbxApp = new ComboBox<SamSystem>();
cbxApp.setWidth(250);
cbxApp.setDisplayField("name");
cbxApp.setValueField("id");
cbxApp.setMinLength(1);
cbxApp.setEmptyText("Select an application...");
cbxApp.setSelectOnFocus(true);
cbxApp.setStore(storeApps);

this.add(new AdapterToolItem(cbxApp));
Regards, Robert

gslender
27 Aug 2008, 1:08 PM
When I try to do this I have to implement a few methods, i.e. update(ModelData model). And I really don't know how to get the combobox updated.


Hi robert - without a complete and full working example, its hard to say what is wrong. You are correct in that you would need to act on the store B add/remove/change events and then do the appropriate add/remove/change on store A

This is about all you would need to do - the store should update the combo for you based on the changes to the store.

zsumore
28 Aug 2008, 7:02 PM
Is it possible to dynamically update a ComboBox? I don't see any way to a bind a store and ComboBox together.

Your help is greatly appreciated!!
Rob

ComboBox.setStore(ListStore<D> store);
ComboBox.getListView().setStore(ListStore<D> store);