Update Row Help
I currently have a table where if I click on the row, it updates the data but it stays on that data and I can't seem to figure out how to get it to switch back between the original data and the new data
var win = Titanium.UI.currentWindow;
// create table view data
var data = [
{title:'Change Me1'},
{title:'Change Me2'},
];
var search = Titanium.UI.createSearchBar({
showCancel:false
});
var tableView = Titanium.UI.createTableView({data:data, search:search, filterAttribute:'title'});
tableView.addEventListener('click',function(e)
{
switch(e.index)
{
case 0:
{
data = {title:'New Row1'};
tableView.updateRow(0,data,{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
break;
}
case 1:
{
data = {title:'New Row2'};
tableView.updateRow(1,data,{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.LEFT});
break;
}
}
});
win.add(tableView);
1 Answer
-
Accepted Answer
Hi J,
This code will do what you want, although without the animation.
var win = Titanium.UI.currentWindow; // create table view data var data = [ {title:'Change Me1', title1: 'Change Me1', title2: 'New Row1'}, {title:'Change Me2', title1: 'Change Me2', title2: 'New Row2'} ]; var search = Titanium.UI.createSearchBar({ showCancel:false }); var tableView = Titanium.UI.createTableView({data:data, search:search, filterAttribute:'title'}); tableView.addEventListener('click',function(e){ if(e.rowData.title == e.rowData.title1) { e.row.title = e.rowData.title2; } else if(e.rowData.title == e.rowData.title2) { e.row.title = e.rowData.title1; } e.row.animate({animationStyle: Titanium.UI.iPhone.RowAnimationStyle.LEFT}); }); win.add(tableView);
Hope that helps!
Cheers,
Angus