Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sencha Touch - deselect list item?

I'm working on a Sencha Touch application, and have a list of contacts. When a list item is tapped, an ActionSheet is displayed showing some basic functions (such as call, delete and ignore). Unfortunately, when the user taps and the ActionSheet is fired, the List item remains selected underneath the overlay (see the screenshot below):

Screenshot of iOS Simulator

Here's the function bound to the itemTap event:

itemTap: function(list, index)
{
    // Deselect the selected record:
    var currentRecord = list.getStore().getAt(index);
    currentRecord.forename      = currentRecord.get('forename');
    currentRecord.surname       = currentRecord.get('surname');
    currentRecord.phoneNumber   = currentRecord.get('phoneNumber');
    currentRecord.shortFullName = currentRecord.forename + ' ' +  currentRecord.surname[0];

    list.getStore().deselect(index, true);

    callButton.setText('Call ' + currentRecord.shortFullName + ' (' + currentRecord.phoneNumber + ')');
    unfriendButton.setText('Remove ' + currentRecord.shortFullName + ' as friend');
    friendActionSheet.show();
}

Unfortunately, list.getStore().deselect(index, true) returns the following error: Object [object Object] has no method 'deselect'

Any ideas on what I could be doing wrong, or how I can achieve this?

like image 266
BenM Avatar asked Mar 20 '11 11:03

BenM


4 Answers

This works for me:

    listeners: {
        itemtap: function(dv, ix, item, e) {
            // Clear the selection soon
            setTimeout(function(){dv.deselect(ix);},500);
        }
    }
like image 121
Chris Avatar answered Oct 20 '22 20:10

Chris


In Sencha Touch 2, use disableSelection: true, while creating a list

Ext.define('App.view.NewsList',{
extend: 'Ext.List',
xtype: NEWS_LIST,

config: {
    store: NEWS_FEED,
    //deselectOnContainerClick: true,// not working in Sencha Touch 2
    disableSelection: true, // since Sencha Touch 2
    itemTpl: '{heading}'
} 
});
like image 40
Sachin Warke Avatar answered Oct 20 '22 22:10

Sachin Warke


If you want to clear the whole list:

var selModel = app.views.notesList.deselect(app.views.notesList.getSelectedRecords());
like image 2
Frode Avatar answered Oct 20 '22 22:10

Frode


setTimeout is really not a good solution here. It should be like this:

 listeners: {
        itemtap: function(list, ix, item, e) {
            // Clear the selection soon
            list.deselect(list.getSelectedRecords());
        }
    }
like image 1
Swar Avatar answered Oct 20 '22 20:10

Swar