Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DataSource: strange behaviour in Chrome

    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:
    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) {
    			}
    		});
    	}
    }
    For test purposes the RPC call to the server just returns a ordered list of dummy strings from this test code:
    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;
    	}

    #2
    Thank you!
    That helped me a lot.

    I have played with it a little bit to display a whole grid as follows (I may post in the following days an improved version):

    Code:
    final DataSource ds = new DataSource();
    		ds.setClientOnly(true);
    		DataSourceTextField postcodeDSField = new DataSourceTextField("postcode", "Post Code");
    		DataSourceTextField countryDSField = new DataSourceTextField("country", "Country");
    		postcodeDSField.setPrimaryKey(true);
    		ds.setFields(postcodeDSField, countryDSField);
            
            final ComboBoxItem searchComboBoxItem = new ComboBoxItem();
    		searchComboBoxItem.setShowTitle(false);
    		searchComboBoxItem.setShowPickerIcon(false);
    		searchComboBoxItem.setValueField("postcode");
    //		searchComboBoxItem.setDisplayField("postcode");
    		searchComboBoxItem.setValue("Search Address");
    		searchComboBoxItem.setTooltip("Search for the full address");
    		searchComboBoxItem.setOptionDataSource(ds);
    		ListGridField postcodeField = new ListGridField("postcode");
    		ListGridField countryField = new ListGridField("country");
    		searchComboBoxItem.setPickListFields(postcodeField, countryField);
    		searchComboBoxItem.setPickListWidth(450);
    		searchComboBoxItem.addKeyUpHandler(new com.smartgwt.client.widgets.form.fields.events.KeyUpHandler(){
    			@Override
    			public void onKeyUp(
    					com.smartgwt.client.widgets.form.fields.events.KeyUpEvent event) {
    				String val = (String) searchComboBoxItem.getValue();
    				
    				String[] suggestions = new String[10];
    				for (int i = 0; i < suggestions.length; i++) {
    					suggestions[i] = val + "Suggestion " + i;
    				}
    				
    				for (int i = 0; i < suggestions.length; i++) {
    					ListGridRecord record = new ListGridRecord();
    					record.setAttribute("postcode", suggestions[i]);
    					record.setAttribute("country", "Random country");
    					ds.addData(record);
    				}	
    			}
    			
    		});
    		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 searchComboForm = new DynamicForm();
    		searchComboForm.setFields(searchComboBoxItem);
    		
    		this.addMember(searchComboForm);

    Comment


      #3
      Note if there is any Chrome-specific odd behavior, see the FAQ - Chrome and GWT have bugs that manifest only in GWT's development mode.

      Comment

      Working...
      X