Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1215] Ti.UI.TableView.data.length returns the original no of rows in table, rather than *current* number of rows

GitHub Issuen/a
Resolution Date2011-04-26T09:15:06.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-12
Labelsandroid, defect, reported-1.3.2, rows, tableview
ReporterPaul Dowsett
AssigneeMarshall Culpepper


Platform: Android, emulator, Ti 1.3.2

Ti.UI.TableView.data.length returns the original no of rows in table, rather than current number of rows

A good example of this problem is in the KitchenSink at http://github.com/appcelerator/KitchenSink/blob/master/KitchenSink/Resources/examples/table_view_row_delete.js"> table_view_row_delete.js which 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('Number of table rows: '+tableview.data.length);
Ti.API.info("deleting row");
Ti.API.info('Number of table rows: '+tableview.data.length);
Ti.API.info(' * * * * * * * * * * * * ');

Incidentally, another issue that may be related is that getData() does not work currently, demonstrated by Ti.API.info('getData type: '+typeof(tableview.getData())); producing an exception.


  1. hal 2011-04-15

    See http://developer.appcelerator.com/question/39391/kitchensink-tableviewdatalength-not-defined"> http://developer.appcelerator.com/question/39391/kitchensink-tablev... for better formatting of the code!

  2. Luke Melia 2011-04-15

    I think that I'm seeing this on iPhone 1.4, too. Is there another way to get the number of rows in the table?

  3. hal 2011-04-15

    Actually, I don't think javascript inherently returns the correct array.length when an element has been removed, because I don't think elements of an array can be deleted - they can only be nulled. After this, the array remains the same length as when it was created.

    Still, as I imagine Ti manages the number of visible rows displayed in a table as an object, hopefully there is a better way of obtaining this information than with array.length.

  4. Stephen Tramer 2011-04-15

    Gonna reassign to Don for triage. Sorry Don!

  5. Joe iEntry 2011-04-15

    Has this issue been resolved?

  6. hal 2011-04-15


    As this ticket is not marked resolved, the issue has not been resolved.

    Note that this system is not the place for a discussion - ask a question in the http://developer.appcelerator.com/questions/created">Q&A if you are looking for suggestions for a workaround.

  7. Don Thorp 2011-04-15

    This ticket is now invalid. Tableview.data returns an array of Sections. You can iterate that array and sum the rows in all sections.

  8. Joe iEntry 2011-04-15


    Don is right, to see an example of how this works, check out this post on the Q&A Forum: http://developer.appcelerator.com/question/117594/number-of-rows-in-table"> Number of Rows in Table

  9. hal 2011-04-15


    I am certain that everyone appreciates your participation, which is welcome and worthwhile. That said, the medium you are choosing to give it is not really appropriate.

    As Don is the lead for the Titanium Android development team, his posts to Lighthouse should typically be considered the definitive view at the time of writing of any issue.

    Bear in mind that the Q&A is a community forum, and hence the views expressed in it are provided on a best-effort basis. As such, there is little point using advice provided in the Q&A to justify a standpoint made in Lighthouse.

    Again, Lighthouse is not the place for discussion, speculation or opinion, which simply create noise and interrupt work on the task at hand.

    Even by writing this post I realize I risk contributing to that noise, but I hope it will be sufficient to encourage you to keep all of your posts strictly factual while always providing sound evidence to support them.

JSON Source