1. #1
    Sencha User treblereel's Avatar
    Join Date
    Mar 2010
    Location
    Moscow,Russia
    Posts
    67
    Vote Rating
    1
    treblereel is on a distinguished road

      0  

    Default Unanswered: How to set default value to ComboBox

    Unanswered: How to set default value to ComboBox


    Hi folks,

    I have problems while i am trying to set default value to ComboBox using departmentComboBox.setValue(departmentStore.getAt(0)). I think, it doesnt work coz store is empty at the moment. How can i fix it ?

    PHP Code:
        private ComboBox<BeanModel> doDepartmentComboBox(){
             ListStore<BeanModel>  departmentStore;
             final DepartmentServiceAsync departmentService = GWT.create(DepartmentService.class);
             ListLoader<?loader;
             
             
    RpcProxy<List<DepartmentDTO>> DepartmentProxy = new RpcProxy<List<DepartmentDTO>>() {
                 @
    Override
                 
    protected void load(Object loadConfigAsyncCallback<List<DepartmentDTO>> callback) {
                     
    departmentService.getDepartments("1",callback);
                 }
             }; 
             
                 
    loader = new BaseListLoader<ListLoadResult<ModelData>>(DepartmentProxy,new BeanModelReader());
                
    departmentStore = new ListStore<BeanModel>(loader);
                
    departmentStore.setMonitorChanges(true);
                
    loader.load();
            
            
            
    departmentComboBox = new ComboBox<BeanModel>();
            
    departmentComboBox.setDisplayField("name");  
            
    departmentComboBox.setWidth(150);
            
    departmentComboBox.setName("department");
            
    departmentComboBox.setFieldLabel("Department");
            
    departmentComboBox.setAllowBlank(false);
            
    departmentComboBox.setEditable(false);
            
    departmentComboBox.setValue(departmentStore.getAt(0));
            
    departmentComboBox.setStore(departmentStore);  
            
    departmentComboBox.setTypeAhead(true);  
            
    departmentComboBox.setTriggerAction(TriggerAction.ALL); 
            
            return 
    departmentComboBox;
        }

  2. #2
    Sencha User
    Join Date
    Jul 2009
    Location
    Trabzon
    Posts
    99
    Vote Rating
    0
    harun is on a distinguished road

      0  

    Thumbs up Solution is too simple

    Solution is too simple


    You must set value after loading data. so you can add setValue(...) method after callback response.

    I advice you:

    Code:
    RpcProxy<List<DepartmentDTO>> DepartmentProxy = new RpcProxy<List<DepartmentDTO>>() { @Override protected void load(Object loadConfig, AsyncCallback<List<DepartmentDTO>> callback) { departmentService.getDepartments("1",callback);
    departmentComboBox.setValue(departmentStore.getAt(0));
    } };
    Best Regards,
    Website: harunates.com
    Blog: blog.harunates.com
    Feel free to contact me harun@harunates.com

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,733
    Answers
    109
    Vote Rating
    90
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    Right idea harun, but I would move that to a listener on the Loader.Load event coming from the loader instance, so that you know that the server has already sent back the results, instead of setting the value as soon as the request is made.

  4. #4
    Sencha User treblereel's Avatar
    Join Date
    Mar 2010
    Location
    Moscow,Russia
    Posts
    67
    Vote Rating
    1
    treblereel is on a distinguished road

      0  

    Default


    thanks for answer. but combox is populating only after i click to combo. How do i can load and set value after attach ? something like Events.attach => combo.getStore.getLoader.load ?

  5. #5
    Sencha User
    Join Date
    Jul 2009
    Location
    Trabzon
    Posts
    99
    Vote Rating
    0
    harun is on a distinguished road

      0  

    Thumbs up


    Hi, you can easily listen attach event like:

    Code:
    myComboBox.addListener( Events.Attach, new Listener<BaseEvent>() {
    			@Override
    			public void handleEvent( BaseEvent be)
    			{
    				// your code what you want
    			}
    		} );
    Website: harunates.com
    Blog: blog.harunates.com
    Feel free to contact me harun@harunates.com

Thread Participants: 2