1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    19
    Vote Rating
    0
    bothwell is on a distinguished road

      0  

    Default Answered: Select multiple list items (programatically from the controller)

    Answered: Select multiple list items (programatically from the controller)


    Probably a question with a really simple answer but I haven't been able to find an answer searching.

    I have a list with some data in it, depending on a setting, some of the list items are to be pre-selected on load. The list has been configured with mode: "multi" and multiple selection works correctly on tap.

    To pre-select list items, I am using this in my controller:
    Code:
                                Ext.each(myData, function(category, index){
                                    if(category.ismember == 1){
                                        myList.select(index);
                                    }
                                });
    This does select items, but it resets the selection on each pass, so only the last index ends up highlighted.

    I've also tried passing in a comma separated list of indexes:

    Code:
                                   myList.select(1, 2);
    ... but that will only select the first index given.

    Is there a way to achieve multiple selections from the controller?

  2. Hi bothwell,

    from the docs (http://docs.sencha.com/touch/2-1/#!/...-method-select):
    keepExisting : Boolean
    If true, the existing selection will be added to (if not, the old selection is replaced).
    So I think you have to set the 2nd parameter to true:
    Code:
    Ext.each(myData, function(category, index){
        if(category.ismember == 1){
            myList.select(index, true);
        }
    });
    I didn't test it, but it sounds plausible

    Best regards,
    Schildi

  3. #2
    Sencha User
    Join Date
    Mar 2011
    Posts
    83
    Answers
    16
    Vote Rating
    11
    Schildi will become famous soon enough

      1  

    Default


    Hi bothwell,

    from the docs (http://docs.sencha.com/touch/2-1/#!/...-method-select):
    keepExisting : Boolean
    If true, the existing selection will be added to (if not, the old selection is replaced).
    So I think you have to set the 2nd parameter to true:
    Code:
    Ext.each(myData, function(category, index){
        if(category.ismember == 1){
            myList.select(index, true);
        }
    });
    I didn't test it, but it sounds plausible

    Best regards,
    Schildi

  4. #3
    Sencha User
    Join Date
    Nov 2012
    Posts
    19
    Vote Rating
    0
    bothwell is on a distinguished road

      0  

    Default


    That is exactly right!

    Some day soon I swear I'll get the hang of finding the right place to look in the docs

    Thank you!

Thread Participants: 1

Tags for this Thread