WebOSDev - Programming has just evolved

The online blog for the webOS developer community you can find everything you need here to get a strong start developing applications for the webOS platform

How to Make SwipeToDelete Dynamic

Posted by codesos Saturday, April 3, 2010



You have to declare in th attributes of the list swipeToDelete: true  to allow the list to delete items , but add this preventDeleteProperty:'noDelete'  also if you want the list to be able to determine which items can be deleted or not.

so for example:
var attributes =
{
    itemTemplate: 'food-filter-list/entry',
    swipeToDelete: true,
    preventDeleteProperty:'noDelete',
    reorderable: false,
    filterFunction: this.FilterList.bind(this),
    formatters:{Food_Item:this.formatName.bind(this),Points:this.formatNumber.bind(this)},
    delay: 500, //1 second delay before filter string is used
    disabledProperty: 'disabled'
 };

this.model = {disabled: false};

this.controller.setupWidget('filterlistID', attributes, this.model); 
this.filterlist = this.controller.get('filterlistID');


the default implementation allows delete of all the items.

Now if you want to allow an item not to be deleted :

entry = {Food_Item: $L(row.Portion + ConnectionWord + row.Food_Item), Points: row.Points,ItemObj:row,'noDelete':true};

this.FoodList[i] = entry;
this way you can dynamically determine which item can be deleted or not

cool , no?


0 comments

Post a Comment