Titanium Community Questions & Answer Archive

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

tableView.setData() appending data not actually setting it

Hi

I am using setData to add rows to my table view. I thought using setData would clear whats already in the table and then reload it with the array I pass to setData???

Right now if I have Row1 and Row2 in the table and use setData for Row3 and Row4 I get Row1, Row2, Row3 and Row4 all added instead of just Row3, Row4 in the table.

Is there a way to clear the table first and then use setData again for the new rows.

I have tried passing in an empty array in the setData function but that doesn't seem to work.

Ian

— asked August 3rd 2010 by Ian Briggs
  • setdata
  • tableview
2 Comments
  • Ok, solved it guys, sorry. Thanks anyway!

    — commented August 3rd 2010 by Ian Briggs
  • How did you solve it?

    — commented March 9th 2011 by Scott Millar

4 Answers

  • Did your clear the array? Look to the kitchensink reload example. In general this should work:

    var arr = [];
    arr.push(row1);
    arr.push(row2);
    tableview.setData(arr);
    
    // reload
    arr = []; // deleting the array!
    arr.push(row3);
    arr.push(row4);
    tableview.setData([]); // you can do that, but don't have to...
    tableview.setData(arr);
    
    — answered November 17th 2010 by Sven Wiese-Solty
    permalink
    0 Comments
  • Yes, I got it.

    I did:

    data = [ ];
    tableView.setData(data);

    Thanks

    — answered November 16th 2010 by Deeksha Prabhakar
    permalink
    0 Comments
  • Deeksha,

    Like Sven mentioned, make sure the array is clear of all data before pushing more data to it. You can also clear the data on tble.setData();


    http://www.srcnix.com

    — answered November 17th 2010 by Steve Clarke
    permalink
    0 Comments
  • Hi,

    Can you please let us know how you solved it?

    Thanks

    — answered November 17th 2010 by Deeksha Prabhakar
    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.