Titanium Community Questions & Answer Archive

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

Updating a Tableview

Hi,

I'm trying to update a tableview when a user clicks a button, through a function.

function emptydata(){
    var data = [];    
}
function popTable(e){
        emptydata();
    set = e;
while(set.isValidRow()){
       data.push(row);
set.next();


}

tableview.setData(data);

}

popTable(dataSet);

However, this doesn't seem to replace the data already in the tableview. It works once, but that's it. Thanks, any help would be greatly appreciated.

On the same note, I'm using a tab based nav system. If I open up a sub window in a tab. How would I refresh the main tab window, if there's new data to pull from the database?

— asked November 1st 2010 by Connor Zwick
  • data
  • tableview
0 Comments

2 Answers

  • CZ

    Is this all of your code? There seems to be some missing. Where is "set" being, err, set?

    Although you are iterating through the result, you are not accessing the data in each row's fields. Use the fieldByName() method of the ResultSet object, explained in the documentation.

    There is also a useful example in the KitchenSink in the scripts database.js and database_2.js. Furthermore there is Kevin Whinnery's Persistence app, although I think most of its functionality is demonstrated in the KitchenSink now.

    Hope this is useful. Post back if it's not what you need.

    Hal

    — answered November 5th 2010 by Paul Dowsett
    permalink
    0 Comments
  • One of the caveats of developing with Titanium is that you also need to understand JavaScript and how to code it properly.

    When you said a local variable inside a function, it does not maintain scope to the rest of your document code.

    You need to set var data =[] outside of all functions to make it global.

    You can then empty it

    data=[]

    and also push more items to it, and use it to set your tableview contents

    example

    var data=[]

    function emptydata(){
    data = [];
    }
    function popTable(e){
    emptydata();
    set = e;
    while(set.isValidRow()){
    data.push(row);
    set.next();

    }

    tableview.setData(data);

    }

    popTable(dataSet);

    — answered November 7th 2010 by Matthew Brennan
    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.