Maxx
Maxx

Reputation: 5

Titanium tableView refresh

How do I add an event listener so that a table is updated when the window/tab is in focus? My Current code works for webViews but I am unsure as how to apply it to tableViews. win.addEventListener('focus',function(e){webview.reload();});

Upvotes: 0

Views: 1645

Answers (3)

MRT
MRT

Reputation: 1610

Yes, You can perform in your current Code.

win.addEventListener('focus', function(e){
    tableView.setData(newData); // this is always add update Array
}); 

for example

var win = Ti.UI.createWindow();
var data = [
    {title:"Row 1"},
    {title:"Row 2"},
    {title:"Row 3"}
];

var tableView = Ti.UI.createTableView({
    data: data
});

win.add(tableView);
win.open();

Try again this

var win = Ti.UI.createWindow();
    var data = [
        {title:"Row 1"},
        {title:"Row 2"},
        {title:"Row 3"}
    ];

    var tableView = Ti.UI.createTableView({
        data: data
    });
data = [
        {title:"Row 1"},
        {title:"Row 2"},
        {title:"Row 3"},
    {title:"Row 4"},
    {title:"Row 5"},
    ];
win.addEventListener('focus',function(){
      tableView.setData(data);
});
win.add(tableView);
win.open();

Upvotes: 0

bad
bad

Reputation: 76

Say you have your table, defined as:

var tableData = [{title: 'Elephants'}, {title: 'Donkeys'}, {title: 'Falcons'}]

var tableView = Ti.UI.createTableView({
    data: tableData
})
win.add(tableView)

And an array called newData that has the new information you want to place in the table. Have you tried doing the following?

win.addEventListener('focus', function(e){
    tableView.data = newData
})

Let me know if you need more information or if this doesn't fit your needs.

Upvotes: 0

Aaron Saunders
Aaron Saunders

Reputation: 33345

create a method that reloads the data for the table and call table.setData(_tableData)

Upvotes: 3

Related Questions