Creating object literals in this way is very handy when pulling data out of a database or across the network. By explicitly creating TableViewRow objects, you gain access to a few handy methods such as add()
or fireEvent()
.
Emptying a table
You can empty a table by setting its data
property to an empty array.
Setting data
vs. setData()
vs. appendRow()
For best performance, create an array of row objects (object literals or explicitly typed) and then assign them to the table using either setData()
or by setting the data
property. In community tests, appendRow()
performs significantly slower than setData()
when adding thousands of rows to a test table. Though this is an uncommon scenario, it is still best to manage your tables, and all UI components, in the most performant manner possible.
If your app does however currently require a table with thousands of rows, you should may want to reconsider your UI. Users won't want to scroll through that many rows to find the one that interests them. Even on the fastest device, such a table will be slow. Consider some sort of drill-down interface, filtering mechanism, or alternate UI/UX paradigm to reduce the size of the available table.
Row indicators
Row indicators are icons that provide visual cues to your users related to your table rows. As shown in the following graphic, Android supports two built-in icons while iOS supports three. Each is a boolean value set with the property listed following the graphic.
hasChild
– indicates sub-table or additional rows (most commonly used on iOS with the navigation controller)hasDetail
– indicates a detail view or alert will appear when row is tapped (not supported on Android)hasCheck
– an on/off or yes/no indicator
This is just one very simple example of how you can create custom rows for your tables. You can literally embed almost any Titanium UI component in any visual configuration to create your rows.