tags:

views:

5000

answers:

2

How do I use ComboBox in EXT-GWT with static data. For example I just want to hard code (for demo purposes) list of First Names and display it to the user. I don't want to use any dummy objects that they are using in their samples. Where can I find simple example with Strings?

+1  A: 

Maksim,

I am not sure whether it helps you or not. It was based on the GWT-EXT for combobox. As I remember that, it wraps the String[] with SimpleStore object.

//create a Store using local array data  
 final Store store = new SimpleStore(new String[]{"abbr", "state", "nick"}, getStates());  
 store.load();  

 final ComboBox cb = new ComboBox();  
 cb.setForceSelection(true);  
 cb.setMinChars(1);  
 cb.setFieldLabel("State");  
 cb.setStore(store);  
 cb.setDisplayField("state");  
 cb.setMode(ComboBox.LOCAL);  
 cb.setTriggerAction(ComboBox.ALL);  
 cb.setEmptyText("Enter state");  
 cb.setLoadingText("Searching...");  
 cb.setTypeAhead(true);  
 cb.setSelectOnFocus(true);  
 cb.setWidth(200);

I hope it helps. Tiger

ps) Did you try this example ?

    // create store 
ListStore<String> store = new ListStore<String>(); 
store.add( Arrays.asList( new String[]{"A","B","C"})); 
ComboBox cb = new ComboBox(); 
cb.setStore(store);
Tiger
Thanks for your response. There is something is wrong with SimpleStore object. It does not exist. I think it is no longer exist in this library.
Maksim
I believe that the ComboBox in Ext-GWT API has setStore(ListStore) function to load data. so we can use as below:(It might be the same as the demo example )// create storeListStore<String> store = new ListStore<String>();store.add( Arrays.asList( new String[]{"A","B","C"}));ComboBox cb = new ComboBox();cb.setStore(store);I hope it helps.
Tiger
Now it complains about String in "ListStore<String>", here is error "Bound mismatch: The type String is not a valid substitute for the bounded parameter <M extends ModelData> of the type ListStore<M>"
Maksim
A: 

Here is the code I use in my project:

SimpleComboBox combo = new SimpleComboBox();
combo.add("One");
combo.add("Two");
combo.add("Three");
combo.setSimpleValue("Two");
KevMo
Ahhhh... Awesome! Thanks KevMo
Maksim
I love it. Thanks
Tiger