Saturday, October 1, 2011

Select Item in sencha touch list on load


Recently I was working on Sencha Touch application. Requirement was to populate list and select a specific item which was selected by user earlier.

Following is the trick to do it.

myList.on('refresh', function(){
       var recordIndex ='field', 'value');,true,false);  
}); returns the index of record that matches the filters and it will be first match of record. So if you have multiple records with same value in field this will not be useful for you. You must need some unique value. will select record in specific index. Second argument is to keep existing selection. In case of multiselect list this will preserve last selection and. Third argument is to suppress the slectionChange event. Sometimes you might have disclosure set on list. So might want to suppress the selection change.

Here select function also accept record or records instead of index. If you have record which were selected earlier, you can directly pass those records in select function as follow.,true,false);

This is how you can select and item in sencha touch list.

No comments:

Post a Comment