-
30 Nov 2012 8:56 AM #1
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:
This does select items, but it resets the selection on each pass, so only the last index ends up highlighted.Code:Ext.each(myData, function(category, index){ if(category.ismember == 1){ myList.select(index); } });
I've also tried passing in a comma separated list of indexes:
... but that will only select the first index given.Code:myList.select(1, 2);
Is there a way to achieve multiple selections from the controller?
-
Best Answer Posted by Schildi
Hi bothwell,
from the docs (http://docs.sencha.com/touch/2-1/#!/...-method-select):
So I think you have to set the 2nd parameter to true:keepExisting : Boolean
If true, the existing selection will be added to (if not, the old selection is replaced).
I didn't test it, but it sounds plausibleCode:Ext.each(myData, function(category, index){ if(category.ismember == 1){ myList.select(index, true); } });
Best regards,
Schildi
-
30 Nov 2012 9:27 AM #2
Hi bothwell,
from the docs (http://docs.sencha.com/touch/2-1/#!/...-method-select):
So I think you have to set the 2nd parameter to true:keepExisting : Boolean
If true, the existing selection will be added to (if not, the old selection is replaced).
I didn't test it, but it sounds plausibleCode:Ext.each(myData, function(category, index){ if(category.ismember == 1){ myList.select(index, true); } });
Best regards,
Schildi
-
30 Nov 2012 9:41 AM #3
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!


Reply With Quote