[TIMOB-1215] Ti.UI.TableView.data.length returns the original no of rows in table, rather than *current* number of rows
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Trivial |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2011-04-26T09:15:06.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.7.0, Sprint 2011-12 |
Components | Android |
Labels | android, defect, reported-1.3.2, rows, tableview |
Reporter | Paul Dowsett |
Assignee | Marshall Culpepper |
Created | 2011-04-15T02:46:47.000+0000 |
Updated | 2011-04-26T09:15:06.000+0000 |
Description
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(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(' * * * * * * * * * * * * ');
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.
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!
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?
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.
Gonna reassign to Don for triage. Sorry Don!
Has this issue been resolved?
Joe
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.
This ticket is now invalid. Tableview.data returns an array of Sections. You can iterate that array and sum the rows in all sections.
Example:
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
Joe
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.