1. #1
    Ext User
    Join Date
    Jul 2009
    Location
    Curitiba Brazil
    Posts
    39
    Vote Rating
    1
    Reghin is on a distinguished road

      0  

    Default How to manually select an item (combobox)

    How to manually select an item (combobox)


    I have a combobox bound to a store. This store is bound to a GWT-RPC service (via proxy) and works well.

    What I need to do is once the data (list of BeanModelTag) returns from the server, manually set the combobox's selected item to the first bean in the list.

    I've tried combobox.setValue as well combobox.select inside the loaderLoad event, but not working.

    Is this event the right place I should put any setValue or select? If not, where?

  2. #2
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default


    Create your combo box and overwrite the method get and set
    Code:
    MyComboBox extends ComboBox
    the behaviour of the combo box should be different.. but the gxt team.. dont change.. so its the soluction..

    other way.. you can use memory proxy.. but its bad.. will store all data of your combobox..

  3. #3
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by fother View Post
    Create your combo box and overwrite the method get and set
    Code:
    MyComboBox extends ComboBox
    the behaviour of the combo box should be different.. but the gxt team.. dont change.. so its the soluction..

    other way.. you can use memory proxy.. but its bad.. will store all data of your combobox..
    This is wrong. Please reread the requirement of the opener.


    The store gets first loaded on the first expand of the list. You could manually load the store and than you could listen to the loade vent and set the first value.

  4. #4
    Ext User fother's Avatar
    Join Date
    Sep 2007
    Location
    Brazil
    Posts
    744
    Vote Rating
    -1
    fother is an unknown quantity at this point

      0  

    Default


    so.. try add a listener in a store when the data finished store and call the method select..

  5. #5
    Ext User
    Join Date
    Jul 2009
    Location
    Curitiba Brazil
    Posts
    39
    Vote Rating
    1
    Reghin is on a distinguished road

      1  

    Default


    Adding a listener to the store solved the problem. =)

    Code:
            storeContrato = new ListStore<BeanModel>(loaderContrato);
            storeContrato.addStoreListener(new StoreListener<BeanModel>() {
                @Override
                @SuppressWarnings("unchecked")
                public void storeDataChanged(StoreEvent<BeanModel> se) {
                    super.storeDataChanged(se);
                    List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
                    if (beans != null && beans.size() == 1) {
                        comboContrato.setValue(beans.get(0));
                    }
                }
            });
    Thank you!!!

  6. #6
    Ext User
    Join Date
    Jan 2011
    Posts
    1
    Vote Rating
    0
    srinivas.itb is on a distinguished road

      0  

    Default


    I have a combo box in GXT wizard. Which has a proxy service & loader to retrieve the elements. How can i load the elements manually instead of loading by automatic ?

  7. #7
    Sencha User
    Join Date
    Feb 2011
    Posts
    3
    Vote Rating
    0
    juanmav82 is on a distinguished road

      0  

    Default


    Quote Originally Posted by sven View Post
    This is wrong. Please reread the requirement of the opener.


    The store gets first loaded on the first expand of the list. You could manually load the store and than you could listen to the loade vent and set the first value.
    Can you explain how to manually load the store using a proxy service?

    Thanks in advance

  8. #8
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by juanmav82 View Post
    Can you explain how to manually load the store using a proxy service?

    Thanks in advance
    You can call the load method of the loader that you have bound to your store.

  9. #9
    Sencha User
    Join Date
    Feb 2011
    Posts
    3
    Vote Rating
    0
    juanmav82 is on a distinguished road

      0  

    Default


    Sven thanks for the fast reply, but still i cant make it work.

    My code is the follow: ( I have been used Reghin's code)

    Code:
                            final ComboBox combobox;
                            combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());
                            combobox.getStore().addStoreListener(new StoreListener<BeanModel>() {
                                @Override
                                @SuppressWarnings("unchecked")
                                public void storeDataChanged(StoreEvent<BeanModel> se) {
                                    super.storeDataChanged(se);
                                    List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
                                    if (beans != null && beans.size() == 1) {
                                        combobox.setValue(beans.get(0));
                                    }
                                }
                            });
    When I click the combobox this fire the listener. But no one item is selected. Can you point me in right direction?

    Thanks in advance

  10. #10
    Sencha User
    Join Date
    Feb 2011
    Posts
    3
    Vote Rating
    0
    juanmav82 is on a distinguished road

      0  

    Default


    I already solve it, I changed my code as follow.

    Thanks!

    Code:
    Long fk = grid.getSelectionModel().getSelectedItem().get(f.getName());
    						combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());						
    						List<BeanModel> beans = (List<BeanModel>) combobox.getStore().getModels();
    						if (beans != null) {
    							int i = 0;
    							Long auxfk;
    							do {
    								auxfk = (Long)beans.get(i).getProperties().get("id");
    								combobox.setValue(beans.get(i));
    								i++;
    							} while (auxfk != fk);
    						}
    Quote Originally Posted by juanmav82 View Post
    Sven thanks for the fast reply, but still i cant make it work.

    My code is the follow: ( I have been used Reghin's code)

    Code:
                            final ComboBox combobox;
                            combobox = (ComboBox) this.itemModificacion.getItemByItemId(f.getName());
                            combobox.getStore().addStoreListener(new StoreListener<BeanModel>() {
                                @Override
                                @SuppressWarnings("unchecked")
                                public void storeDataChanged(StoreEvent<BeanModel> se) {
                                    super.storeDataChanged(se);
                                    List<BeanModel> beans = (List<BeanModel>) se.getStore().getModels();
                                    if (beans != null && beans.size() == 1) {
                                        combobox.setValue(beans.get(0));
                                    }
                                }
                            });
    When I click the combobox this fire the listener. But no one item is selected. Can you point me in right direction?

    Thanks in advance