Search code examples
sencha-touchsencha-touch-2.3

Sencha Touch default item selection in list


by default how to select first item in list, without tapping it? below is the my view.

Ext.define('MyApp.view.TestList', {
    extend: 'Ext.List',
    xtype: 'testlist',
    config: {
        flex: 1,
        enableSelection: true,
        itemTpl: '{item}',
        data: [
            {item: 'item-1'},
            {item: 'item-2'},
            {item: 'item-3'},
            {item: 'item-4'}
        ]
    }
});

Solution

  • Ext.List has two methods that will help you:

    list.select( record, keepExisting, surpessEvent );
    list.selectRange( startRecordIndex, endRecordIndex, keepExisting );
    

    In your case you can you use list.selectRange( 1, 1, false ); to select the second data record.