I've build my own suggestBox as shown in the code below. I use a DataSource to fill a ComboBoxItem, when my server suggestions are received. The suggestions arrive in sorted order, which both IE and FireFox are perfectly happy to uphold...BUT Chrome (version 7.0) reorders the suggestions in a pretty non-deterministic way.
Here is the code in question (I'm using smartGWT 2.2 & GWT 2.0.4)
Client:
For test purposes the RPC call to the server just returns a ordered list of dummy strings from this test code:
Here is the code in question (I'm using smartGWT 2.2 & GWT 2.0.4)
Client:
Code:
public class SmartGWTTestCanvas implements EntryPoint {
ComboBoxItem searchComboBoxItem;
final String SEARCH_STR = "Search!!";
private final SuggestServiceAsync suggestService = GWT.create(SuggestService.class);
public void onModuleLoad() {
VLayout mainCanvas = new VLayout();
searchComboBoxItem = new ComboBoxItem();
searchComboBoxItem.setShowTitle(false);
searchComboBoxItem.setWidth(130);
searchComboBoxItem.setShowPickerIcon(false);
searchComboBoxItem.setValueField("name");
searchComboBoxItem.setDisplayField("name");
searchComboBoxItem.setValue(SEARCH_STR);
searchComboBoxItem.setTooltip("Search for something here...");
searchComboBoxItem.addKeyUpHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
String val = (String) searchComboBoxItem.getValue();
getSuggestions(val);
}
});
searchComboBoxItem.addClickHandler(new com.smartgwt.client.widgets.form.fields.events.ClickHandler() {
@Override
public void onClick(com.smartgwt.client.widgets.form.fields.events.ClickEvent event) {
searchComboBoxItem.setValue("");
}
});
DynamicForm form = new DynamicForm();
form.setFields(searchComboBoxItem);
mainCanvas.addChild(form);
RootPanel.get("testContainer").add(mainCanvas);
}
private void getSuggestions(String prefix) {
suggestService.getSuggestions(prefix, new AsyncCallback<String[]>() {
public void onSuccess(String[] suggestions) {
DataSource ds = new DataSource();
ds.setClientOnly(true);
DataSourceTextField nameField = new DataSourceTextField("name", "name");
nameField.setPrimaryKey(true);
ds.setFields(nameField);
for (int i = 0; i < suggestions.length; i++) {
ListGridRecord record = new ListGridRecord();
record.setAttribute("name", suggestions[i]);
ds.addData(record);
}
searchComboBoxItem.setOptionDataSource(ds);
}
public void onFailure(Throwable caught) {
}
});
}
}
Code:
public String[] getSuggestions(String prefix) {
String[] suggestions = new String[10];
for (int i = 0; i < suggestions.length; i++) {
suggestions[i] = prefix + "Suggestion " + i;
}
return suggestions;
}
Comment