Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: [CLOSED] ComboBox select scrollIntoView bug

  1. #1
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default [CLOSED] ComboBox select scrollIntoView bug

    GXT Version 1.2.2
    Browsers: Safari, Firefox, IE 7

    The ComboBox select method internally calls scrollIntoView. However, when the list is expanded the selected item is not displayed correctly in the scroll container.

    Here's some sample code to demonstrate the problem. The sample code selects item 75 in the list, which simulates setting a default value. When the trigger click listener is fired, I would expect item 75 to be scrolled into view.

    Code:
    package com.sandbox.client;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.extjs.gxt.ui.client.Events;
    import com.extjs.gxt.ui.client.data.BaseModelData;
    import com.extjs.gxt.ui.client.event.BaseEvent;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.widget.LayoutContainer;
    import com.extjs.gxt.ui.client.widget.form.ComboBox;
    import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Sandbox implements EntryPoint {
    
    	/**
    	 * This is the entry point method.
    	 */
    	public void onModuleLoad() {
    		LayoutContainer container = new LayoutContainer();
    
    		final ListStore<Data> data = new ListStore<Data>();
    		data.add(loadData());
    
    		final ComboBox<Data> combo = new ComboBox<Data>();
    		combo.setEmptyText("Select an item...");
    		combo.setDisplayField("item");
    		combo.setWidth(150);
    		combo.setStore(data);
    		combo.setTypeAhead(true);
    		combo.setTriggerAction(TriggerAction.ALL);
    
    		// Set the value (simulate default value)
    		combo.setValue(data.getAt(75));
    
    		combo.addListener(Events.Expand, new Listener() {
    
    			public void handleEvent(BaseEvent be) {
    				combo.select(75);
    			}
    
    		});
    
    		combo.addListener(Events.TriggerClick, new Listener() {
    
    			public void handleEvent(BaseEvent be) {
    				combo.select(75);
    			}
    
    		});
    
    		container.add(combo);
    
    		RootPanel.get().add(container);
    
    	}
    
    	public List<Data> loadData() {
    		List<Data> data = new ArrayList<Data>();
    		for ( int i = 0; i < 100; i++ ) {
    			data.add(new Data(Integer.toString(i)));
    		}
    
    		return data;
    
    	}
    
    	class Data extends BaseModelData {
    
    		public Data(String item) {
    			setItem(item);
    
    		}
    
    		public void setItem(String item) {
    			set("item", item);
    		}
    
    		public String getItem() {
    			return get("item");
    		}
    	}
    }

  2. #2
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default

    Any update on this bug?

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    It is on the list. Updates will be posted as soon as they are there

  4. #4
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default

    Great!

    thanks for the reply.

  5. #5
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    No bug

    Code:
        combo.addListener(Events.Expand, new Listener<FieldEvent>() {
          public void handleEvent(final FieldEvent fe) {
            DeferredCommand.addCommand(new Command() {
              public void execute() {
                ((ComboBox) fe.component).select(75);
    
              }
            });
          }
        });

  6. #6
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default

    Sorry, Sven - that code fragment doesn't solve the problem.

    Tested using GXT 1.2.2
    Hosted mode
    Safari - OSX
    FireFox - OSX, XP SP2
    IE 7 - XP SP2
    Last edited by les; 11 Feb 2009 at 2:58 PM. Reason: added testing results

  7. #7
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    Have you removed the TriggerClick listener? For me it is working fine.

  8. #8
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default

    yes, I did remove the trigger click listener.

    To to be clear - when the list is expanded (via user click on the combobox), the item that is selected (item 75) should be scrolled into view.

    Here's a new version of the code with your suggestion:

    Code:
    package com.sandbox.client;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import com.extjs.gxt.ui.client.Events;
    import com.extjs.gxt.ui.client.data.BaseModelData;
    import com.extjs.gxt.ui.client.event.FieldEvent;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.store.ListStore;
    import com.extjs.gxt.ui.client.widget.LayoutContainer;
    import com.extjs.gxt.ui.client.widget.form.ComboBox;
    import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.Command;
    import com.google.gwt.user.client.DeferredCommand;
    import com.google.gwt.user.client.ui.RootPanel;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class Sandbox implements EntryPoint {
    
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
            LayoutContainer container = new LayoutContainer();
    
            final ListStore<Data> data = new ListStore<Data>();
            data.add(loadData());
    
            final ComboBox<Data> combo = new ComboBox<Data>();
            combo.setEmptyText("Select an item...");
            combo.setDisplayField("item");
            combo.setWidth(150);
            combo.setStore(data);
            combo.setTypeAhead(true);
            combo.setTriggerAction(TriggerAction.ALL);
    
            // Set the value (simulate default value)
            combo.setValue(data.getAt(75));
    
            combo.addListener(Events.Expand, new Listener<FieldEvent>() {
                 public void handleEvent(final FieldEvent fe) {
                   DeferredCommand.addCommand(new Command() {
                     public void execute() {
                       ((ComboBox<Data>) fe.component).select(75);
    
                     }
                   });
                 }
            });
    
            container.add(combo);
    
            RootPanel.get().add(container);
    
        }
    
        public List<Data> loadData() {
            List<Data> data = new ArrayList<Data>();
            for ( int i = 0; i < 100; i++ ) {
                data.add(new Data(Integer.toString(i)));
            }
    
            return data;
    
        }
    
        class Data extends BaseModelData {
    
            public Data(String item) {
                setItem(item);
    
            }
    
            public void setItem(String item) {
                set("item", item);
            }
    
            public String getItem() {
                return get("item");
            }
        }
    }

  9. #9
    Ext GWT Premium Member les's Avatar
    Join Date
    Sep 2008
    Posts
    48

    Default

    Have you tried the new code fragment to verify that this is still a bug?

  10. #10
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    That code works fine for me.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •