1. #1
    Ext User
    Join Date
    Dec 2010
    Posts
    6
    Vote Rating
    0
    msimone is on a distinguished road

      0  

    Default ListView multi selection - select items programmatically

    ListView multi selection - select items programmatically


    Good evening everybody,

    I'd like to select programmatically several items of a multiselection listview.

    Can some one please tellme how to do that?

    Thanks

    Best Regars

    Matteo

  2. #2
    Sencha User
    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


    I'd like to select programmatically several items of a multiselection listview.

    Can some one please tellme how to do that?
    The selectionmodel as public methods to select items, you probably want to use one of them:

    listView.getSelectionModel() will return you the selectionmodel.

  3. #3
    Ext User
    Join Date
    Dec 2010
    Posts
    6
    Vote Rating
    0
    msimone is on a distinguished road

      0  

    Default


    Thanks for reply.

    I have a custom inherited BaseModelData list and I tried to fill the list into the listView and select all them in this way:

    List<ModuloModelData> listObj = new List<ModuloModelData>();

    listObj = getObjects();

    listView.getSelectionModel().getSelectionModel().setSelection(listObj);
    listView.getSelectionModel().selectAll();

    Where MOduloModelData is an objet inherited from BaseModelData and hetObjects() is a method that return a listo of ModuliModelData.

    The result is a combobox filled with the values but none of them is selected.

    Any suggestion, please?

    Thaks

    Matteo

  4. #4
    Sencha User
    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


    The result is a combobox filled with the values but none of them is selected.

    Any suggestion, please?
    A ComboBox can only have one item, and you need to set it with setValue.

    A ComboBox is not a ListView.

  5. #5
    Ext User
    Join Date
    Dec 2010
    Posts
    6
    Vote Rating
    0
    msimone is on a distinguished road

      0  

    Default


    Sorry Sven,

    I would mean ListView not ComboBox.
    The ListView I' using is defined in this way:

    private ListView<ModuloModelData> listView

    Thaks

  6. #6
    Sencha User
    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


    Please post a fully working testcase that implements EntryPoint, demonstrates exactly what you are doing and is runnable without further depencies.

  7. #7
    Ext User
    Join Date
    Dec 2010
    Posts
    6
    Vote Rating
    0
    msimone is on a distinguished road

      0  

    Default


    Code:
     ListStore<ModuloModelData> moduliStore = new ListStore<ModuloModelData>();
    			 
    		
    			 List<ModuloModelData> listModuloStore =new ArrayList<ModuloModelData>();
    			 listModuloStore.add(new ModuloModelData(1,"SAAB","9000"));
    			 listModuloStore.add(new ModuloModelData(1,"SAAB","9002"));
    			 listModuloStore.add(new ModuloModelData(1,"SAAB","9003"));
    			 moduliStore.add(listModuloStore); 
    			 
    			 List<ModuloModelData> listSubModuloStore =new ArrayList<ModuloModelData>();
    				
    			 
    			 listSubModuloStore.add(new ModuloModelData(3,"VW","GOLF"));
    			 listSubModuloStore.add(new ModuloModelData(4,"Peugeot","307"));
    			
    			 ListViewSelectionModel<ModuloModelData> listViewSelectionModel= new       ListViewSelectionModel<ModuloModelData>();
    			 listViewSelectionModel.setSelectionMode(SelectionMode.MULTI);
    			 
    			//THROWS NULLPOINTER EXCEPTION
    			 listViewSelectionModel.select(listSubModuloStore, true); 
    		
    			 
    			 listViewSelectionModel.selectAll();
    			 
    		 
    		    modulo = new ListView<ModuloModelData>();
    		    modulo.setStore(moduliStore);
    	
    			modulo.setSimpleTemplate("<i>{nome}</i> <b>{nota}</b>");
    			
    		
    			
    	
    		    modulo.setSelectionModel(listViewSelectionModel);
    		    modulo.getSelectionModel().selectAll();
    What is wrong? tnx

  8. #8
    Sencha User
    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


    //THROWS NULLPOINTER EXCEPTION
    listViewSelectionModel.select(listSubModuloStore, true);
    Its because listviewselectionmodel is not set on a ListView yet.


    I just did a small testcase against GXT 2.2.1 and it works fine for me. Which version are you using?

  9. #9
    Ext User
    Join Date
    Dec 2010
    Posts
    6
    Vote Rating
    0
    msimone is on a distinguished road

      0  

    Default


    Hi Sven,

    thankyou very much.

    Solved.

    I'm using 2.1.0 verison of GXT.

    Now I'm goint to use the RPC proxy loader mode to take Items from the server.

    Thaks

    Matteo

Similar Threads

  1. Programmatically Select TreeNode
    By kgmoney in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 8 Feb 2013, 5:16 AM
  2. Replies: 0
    Last Post: 18 Nov 2010, 7:42 AM
  3. Programmatically Select Items in ItemSelector
    By ExtJSBeginner in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 14 Jun 2010, 2:37 PM
  4. ListView.select doesn't work before ListView is displayed for the first time
    By Erich Kitzmueller in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 21 Apr 2010, 12:59 PM
  5. Multi-Select cell selection model, how to create?
    By DragonFist in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 1 May 2008, 7:28 AM

Thread Participants: 1