Titanium Community Questions & Answer Archive

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

KitchenSink tableview.data.length not defined

Note: the title of this post should be tableview.data.length does not return the current number of rows.

Platform: Android, emulator, Ti 1.3.2

How can I determine the number of rows in a tableView at any given time?

An example in the KS at table_view_row_delete.js results in an exception after row 5 is deleted, because tableview.data.length-1 on line 52 always returns 4 (and after row 5 is deleted, id 4 no longer exists).

Inserting this code at line 49 and opening the delete row page will make the problem clear:

Ti.API.info('****************************');
Ti.API.info(typeof(tableview));
Ti.API.info(typeof(tableview.data));
Ti.API.info(typeof(tableview.data.length));
Ti.API.info('Number of table rows: '+tableview.data.length);
tableview.deleteRow(tableview.data.length-1);
Ti.API.info("deleting row");
Ti.API.info('Number of table rows: '+tableview.data.length);
Ti.API.info('****************************');

I'd appreciate it if some Ti people could confirm whether or not this is a bug, and whether there is a workaround?

Much appreciated

— asked June 29th 2010 by Paul Dowsett
  • android
  • emulator
0 Comments

3 Answers

  • Accepted Answer

    Also getting an error with tableview.data and tableview.getData().

    On iOS it always returns 1 and I can't actually access/loop through the data.

    — answered February 17th 2011 by Daniel Andersson
    permalink
    2 Comments
    • Daniel

      This issue is now being tracked in ticket #1215. You can sign up and watch it to receive an email when it is resolved.

      — commented February 17th 2011 by Paul Dowsett
    • That link no longer works and I am still experiencing this issue, how can I track it?

      — commented August 12th 2011 by Andrew Gertig
  • This is an 1 year old question, but I found myself in trouble to get the answer for this problem, so this is what I did to work:

    var row1 = Ti.UI.createTableViewRow({...});
    (...)
    tableview.appendRow(row1);
    tableview.appendRow(row2);
    (...)
    Ti.API.info("Number of table rows: " + tableview.[0].rows.length);
    
    — answered March 13th 2012 by José Júnior
    permalink
    1 Comment
    • Old answer but the correct information is here:
      http://developer.appcelerator.com/question/117594/number-of-rows-in-table#204858

      also tableview.[0] is a syntax error, needs to be tableview.data[0].rows.length

      — commented October 8th 2013 by Michiel D
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.