PDA

View Full Version : SimpleComboBox -> sort



soma13
17 Dec 2011, 8:58 AM
Hi All,

I want to sort items of SimpleComboBox<String> after I added a new item to it dynamically.

Is there a good solution to sort item of a SimpleComboBox<String>?

Example:
SimpleComboBox<String> = ...
...
String newItem = "a new item";
simpleComboBox.add(newItem );
simpleComboBox.setSimpleValue(maxDistance);
// now, have to reorder items of it


thx

daddieke
18 Dec 2011, 1:29 AM
I don't use this but I suppose you can sort the Store of a SimpleComboBox too.

soma13
19 Dec 2011, 12:15 AM
Hi,

Thank you for your answer. After it I have found the good solution:

(1) I have made a base modell data and a store:
public class Apple extends BaseModelData
ListStore<Apple> appleStore = new ListStore<Apple>();

(2) I made a good working equals method!
Example: http://javarevisited.blogspot.com/2011/02/how-to-write-equals-method-in-java.html
(http://javarevisited.blogspot.com/2011/02/how-to-write-equals-method-in-java.html)
(3) I use ComboBox instead of SimpleComboBox

(4) add a new item and sort my store:
Apple newAppleModel = new Apple( "red", 13);
if ( ! appleStore.contains(newAppleModel) ) // it uses the equals method!
{
appleStore.add(newAppleModel);
}

appleStore.sort("weight", SortDir.ASC);
appleCombobox.setValue(newAppleModel);


Thx

LaurentT
15 Feb 2012, 1:45 AM
Use
yourSimpleComboBox.getStore().sort("value", SortDir.ASC);

This "value" string is the id field used by Ext GWT for SimpleComboBox