Titanium Community Questions & Answer Archive

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

Append row to a section

There is a handy method to append new rows to a table but I do not see away to append rows to a section.The following code does not work as expected.

tableView.data[0].rowCount; // as an example reports 0
tableView.data[0].add(newRow);
tableView.data[0].rowCount; // would report 1 now

The row may have been added but it does not show up. Adding new rows with tableView.appendrow(newRow) adds the row to the end of the table only.

Has anyone found a work around for this? I suppose I could use several tables in place of my single table but then I'd have to keep on top of my table height so that it all displays and doesn't appear to be viewable inside of a tiny window. If a tableView is put inside of a view or scroll would it then expand without me needing to resize or track the height of anything?

— asked August 13th 2010 by Michael Stack
  • add
  • append
  • mobile
  • tableview
  • tableviewsection
0 Comments

3 Answers

  • You could try

    the_table.insertRowAfter( row_id , the_row_to_be_inserted )
    

    where row_id is the Index of the last row in the section you want to insert. You will have calculate this row_id as a sum the rows found in the sections 0-X( X being the section you are inserting the row).

    Hope it makes sense, and it's not tested :)

    — answered August 13th 2010 by Dan Tamas
    permalink
    1 Comment
    • This was very close. Just tried this and I am able to get rows in about the right place but if a section has no rows at all it will add the row to the previous section.

      — commented August 13th 2010 by Michael Stack
  • I just want to share that I have succesfully displayed the new rows inserted by adding two lines of code for 'refreshing' the tableview.

    tableView.data[0].rowCount; // as an example reports 0
    tableView.data[0].add(newRow);
    tableView.data[0].rowCount; // would report 1 now
    
    var temp = tableView.data; // save the data into a temporary variable
    tableView.setData(temp); // set the data back to refresh the tableview
    

    Hope this helps…

    — answered June 6th 2011 by Rifani Frestiyanto
    permalink
    2 Comments
    • Thank you, this did help!

      — commented August 9th 2011 by Nathan Rambarran
    • thanks i think its the best solution til now

      — commented May 22nd 2013 by João Serra
  • I have the same problem! I am trying a workaround by having nested tables…will let you know how that goes..

    — answered August 10th 2011 by Ricky Chandarana
    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.