Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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);
— asked October 14th 2010 by J W
  • tableview
  • updaterow
0 Comments

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

    — answered October 14th 2010 by Angus Peart
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.