@maccesar/titools 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS-TEMPLATE.md +173 -0
- package/README.md +867 -0
- package/agents/ti-researcher.md +108 -0
- package/bin/titools.js +53 -0
- package/lib/commands/agents.js +126 -0
- package/lib/commands/install.js +188 -0
- package/lib/commands/uninstall.js +215 -0
- package/lib/commands/update.js +159 -0
- package/lib/config.js +119 -0
- package/lib/downloader.js +153 -0
- package/lib/installer.js +253 -0
- package/lib/platform.js +108 -0
- package/lib/symlink.js +142 -0
- package/lib/utils.js +270 -0
- package/package.json +67 -0
- package/skills/alloy-expert/SKILL.md +247 -0
- package/skills/alloy-expert/assets/ControllerAutoCleanup.js +182 -0
- package/skills/alloy-expert/references/alloy-structure.md +381 -0
- package/skills/alloy-expert/references/anti-patterns.md +133 -0
- package/skills/alloy-expert/references/code-conventions.md +469 -0
- package/skills/alloy-expert/references/contracts.md +280 -0
- package/skills/alloy-expert/references/controller-patterns.md +520 -0
- package/skills/alloy-expert/references/error-handling.md +484 -0
- package/skills/alloy-expert/references/examples.md +735 -0
- package/skills/alloy-expert/references/migration-patterns.md +298 -0
- package/skills/alloy-expert/references/patterns.md +448 -0
- package/skills/alloy-expert/references/performance-patterns.md +855 -0
- package/skills/alloy-expert/references/security-patterns.md +847 -0
- package/skills/alloy-expert/references/state-management.md +779 -0
- package/skills/alloy-expert/references/testing.md +872 -0
- package/skills/alloy-guides/SKILL.md +214 -0
- package/skills/alloy-guides/references/CLI_TASKS.md +243 -0
- package/skills/alloy-guides/references/CONCEPTS.md +191 -0
- package/skills/alloy-guides/references/CONTROLLERS.md +298 -0
- package/skills/alloy-guides/references/MODELS.md +1028 -0
- package/skills/alloy-guides/references/PURGETSS.md +56 -0
- package/skills/alloy-guides/references/VIEWS_DYNAMIC.md +242 -0
- package/skills/alloy-guides/references/VIEWS_STYLES.md +388 -0
- package/skills/alloy-guides/references/VIEWS_WITHOUT_CONTROLLERS.md +109 -0
- package/skills/alloy-guides/references/VIEWS_XML.md +558 -0
- package/skills/alloy-guides/references/WIDGETS.md +176 -0
- package/skills/alloy-howtos/SKILL.md +203 -0
- package/skills/alloy-howtos/references/best_practices.md +138 -0
- package/skills/alloy-howtos/references/cli_reference.md +253 -0
- package/skills/alloy-howtos/references/config_files.md +87 -0
- package/skills/alloy-howtos/references/custom_tags.md +147 -0
- package/skills/alloy-howtos/references/debugging_troubleshooting.md +101 -0
- package/skills/alloy-howtos/references/samples.md +167 -0
- package/skills/purgetss/SKILL.md +442 -0
- package/skills/purgetss/assets/purgetss.config.cjs +17 -0
- package/skills/purgetss/references/EXAMPLES.md +247 -0
- package/skills/purgetss/references/animation-system.md +1294 -0
- package/skills/purgetss/references/apply-directive.md +375 -0
- package/skills/purgetss/references/arbitrary-values.md +612 -0
- package/skills/purgetss/references/class-index.md +1350 -0
- package/skills/purgetss/references/cli-commands.md +948 -0
- package/skills/purgetss/references/configurable-properties.md +654 -0
- package/skills/purgetss/references/custom-rules.md +161 -0
- package/skills/purgetss/references/customization-deep-dive.md +722 -0
- package/skills/purgetss/references/dynamic-component-creation.md +489 -0
- package/skills/purgetss/references/grid-layout.md +455 -0
- package/skills/purgetss/references/icon-fonts.md +609 -0
- package/skills/purgetss/references/installation-setup.md +366 -0
- package/skills/purgetss/references/opacity-modifier.md +291 -0
- package/skills/purgetss/references/platform-modifiers.md +479 -0
- package/skills/purgetss/references/smart-mappings.md +42 -0
- package/skills/purgetss/references/titanium-resets.md +359 -0
- package/skills/purgetss/references/ui-ux-design.md +1526 -0
- package/skills/ti-guides/SKILL.md +94 -0
- package/skills/ti-guides/references/advanced-data-and-images.md +19 -0
- package/skills/ti-guides/references/alloy-cli-advanced.md +84 -0
- package/skills/ti-guides/references/alloy-data-mastery.md +29 -0
- package/skills/ti-guides/references/alloy-widgets-and-themes.md +19 -0
- package/skills/ti-guides/references/android-manifest.md +97 -0
- package/skills/ti-guides/references/app-distribution.md +258 -0
- package/skills/ti-guides/references/application-frameworks.md +377 -0
- package/skills/ti-guides/references/cli-reference.md +402 -0
- package/skills/ti-guides/references/coding-best-practices.md +102 -0
- package/skills/ti-guides/references/commonjs-advanced.md +134 -0
- package/skills/ti-guides/references/hello-world.md +100 -0
- package/skills/ti-guides/references/hyperloop-native-access.md +62 -0
- package/skills/ti-guides/references/javascript-primer.md +411 -0
- package/skills/ti-guides/references/reserved-words.md +36 -0
- package/skills/ti-guides/references/resources.md +183 -0
- package/skills/ti-guides/references/style-and-conventions.md +48 -0
- package/skills/ti-guides/references/tiapp-config.md +609 -0
- package/skills/ti-howtos/SKILL.md +174 -0
- package/skills/ti-howtos/references/android-platform-deep-dives.md +658 -0
- package/skills/ti-howtos/references/automation-fastlane-appium.md +95 -0
- package/skills/ti-howtos/references/buffer-codec-streams.md +140 -0
- package/skills/ti-howtos/references/cross-platform-development.md +348 -0
- package/skills/ti-howtos/references/debugging-profiling.md +543 -0
- package/skills/ti-howtos/references/extending-titanium.md +723 -0
- package/skills/ti-howtos/references/google-maps-v2.md +169 -0
- package/skills/ti-howtos/references/ios-map-kit.md +143 -0
- package/skills/ti-howtos/references/ios-platform-deep-dives.md +783 -0
- package/skills/ti-howtos/references/local-data-sources.md +301 -0
- package/skills/ti-howtos/references/location-and-maps.md +252 -0
- package/skills/ti-howtos/references/media-apis.md +210 -0
- package/skills/ti-howtos/references/notification-services.md +599 -0
- package/skills/ti-howtos/references/remote-data-sources.md +349 -0
- package/skills/ti-howtos/references/tutorials.md +502 -0
- package/skills/ti-howtos/references/using-modules.md +237 -0
- package/skills/ti-howtos/references/web-content-integration.md +307 -0
- package/skills/ti-howtos/references/webpack-build-pipeline.md +78 -0
- package/skills/ti-ui/SKILL.md +179 -0
- package/skills/ti-ui/references/accessibility-deep-dive.md +242 -0
- package/skills/ti-ui/references/animation-and-matrices.md +599 -0
- package/skills/ti-ui/references/application-structures.md +655 -0
- package/skills/ti-ui/references/custom-fonts-styling.md +579 -0
- package/skills/ti-ui/references/event-handling.md +393 -0
- package/skills/ti-ui/references/gestures.md +473 -0
- package/skills/ti-ui/references/icons-and-splash-screens.md +409 -0
- package/skills/ti-ui/references/layouts-and-positioning.md +462 -0
- package/skills/ti-ui/references/listviews-and-performance.md +619 -0
- package/skills/ti-ui/references/orientation.md +362 -0
- package/skills/ti-ui/references/platform-ui-android.md +635 -0
- package/skills/ti-ui/references/platform-ui-ios.md +469 -0
- package/skills/ti-ui/references/scrolling-views.md +252 -0
- package/skills/ti-ui/references/tableviews.md +568 -0
|
@@ -0,0 +1,568 @@
|
|
|
1
|
+
# TableViews
|
|
2
|
+
|
|
3
|
+
## Table of Contents
|
|
4
|
+
|
|
5
|
+
- [TableViews](#tableviews)
|
|
6
|
+
- [Table of Contents](#table-of-contents)
|
|
7
|
+
- [1. Overview](#1-overview)
|
|
8
|
+
- [2. TableView vs ListView](#2-tableview-vs-listview)
|
|
9
|
+
- [3. Creating a TableView](#3-creating-a-tableview)
|
|
10
|
+
- [Basic TableView](#basic-tableview)
|
|
11
|
+
- [4. Creating rows](#4-creating-rows)
|
|
12
|
+
- [Object Literal Rows (Simple)](#object-literal-rows-simple)
|
|
13
|
+
- [Explicit TableViewRow Objects](#explicit-tableviewrow-objects)
|
|
14
|
+
- [Performance: setData() vs appendRow()](#performance-setdata-vs-appendrow)
|
|
15
|
+
- [5. Row Properties](#5-row-properties)
|
|
16
|
+
- [Built-in Row Properties](#built-in-row-properties)
|
|
17
|
+
- [Styled Rows Example](#styled-rows-example)
|
|
18
|
+
- [Row Indicators](#row-indicators)
|
|
19
|
+
- [6. Custom Rows](#6-custom-rows)
|
|
20
|
+
- [Adding Child Views](#adding-child-views)
|
|
21
|
+
- [Performance Warning](#performance-warning)
|
|
22
|
+
- [7. Headers and Footers](#7-headers-and-footers)
|
|
23
|
+
- [Table-Level Headers/Footers](#table-level-headersfooters)
|
|
24
|
+
- [Custom Header/Footer Views](#custom-headerfooter-views)
|
|
25
|
+
- [Section Headers/Footers](#section-headersfooters)
|
|
26
|
+
- [8. Grouped Table Style (iOS)](#8-grouped-table-style-ios)
|
|
27
|
+
- [9. Editing Mode](#9-editing-mode)
|
|
28
|
+
- [10. TableView Events](#10-tableview-events)
|
|
29
|
+
- [Click Event](#click-event)
|
|
30
|
+
- [Delete Event](#delete-event)
|
|
31
|
+
- [Scroll Events](#scroll-events)
|
|
32
|
+
- [11. Searching](#11-searching)
|
|
33
|
+
- [12. Updating Table Data](#12-updating-table-data)
|
|
34
|
+
- [Appending Rows](#appending-rows)
|
|
35
|
+
- [Inserting Rows](#inserting-rows)
|
|
36
|
+
- [Deleting Rows](#deleting-rows)
|
|
37
|
+
- [Updating Specific Row](#updating-specific-row)
|
|
38
|
+
- [13. TableView Sections](#13-tableview-sections)
|
|
39
|
+
- [Creating Sections](#creating-sections)
|
|
40
|
+
- [Custom Section Headers](#custom-section-headers)
|
|
41
|
+
- [14. Performance Optimization](#14-performance-optimization)
|
|
42
|
+
- [Use className](#use-classname)
|
|
43
|
+
- [Avoid Too Many Rows](#avoid-too-many-rows)
|
|
44
|
+
- [Optimize Custom Rows](#optimize-custom-rows)
|
|
45
|
+
- [15. Common Patterns](#15-common-patterns)
|
|
46
|
+
- [Detail View Navigation](#detail-view-navigation)
|
|
47
|
+
- [Row Actions (Swipe to Delete)](#row-actions-swipe-to-delete)
|
|
48
|
+
- [Refresh Control](#refresh-control)
|
|
49
|
+
- [16. Platform Differences](#16-platform-differences)
|
|
50
|
+
- [iOS](#ios)
|
|
51
|
+
- [Android](#android)
|
|
52
|
+
- [17. Migration: TableView to ListView](#17-migration-tableview-to-listview)
|
|
53
|
+
- [Best Practices](#best-practices)
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## 1. Overview
|
|
58
|
+
|
|
59
|
+
TableView is a scrolling list component that displays rows of data. While ListView is the recommended modern API for most use cases, TableView remains useful for:
|
|
60
|
+
- Complex row animations
|
|
61
|
+
- Direct child view access
|
|
62
|
+
- Legacy code compatibility
|
|
63
|
+
- UI patterns requiring direct row manipulation
|
|
64
|
+
|
|
65
|
+
## 2. TableView vs ListView
|
|
66
|
+
|
|
67
|
+
| Feature | TableView | ListView |
|
|
68
|
+
| ------------------- | ------------------------------- | ---------------------------- |
|
|
69
|
+
| **Recommended for** | Legacy apps, complex animations | New apps, large datasets |
|
|
70
|
+
| **Data binding** | Direct row object access | Template-based binding |
|
|
71
|
+
| **Performance** | Good for small datasets | Optimized for large datasets |
|
|
72
|
+
| **Row access** | Direct children access | Virtual, data-only updates |
|
|
73
|
+
| **Animations** | Full row animation support | Limited |
|
|
74
|
+
| **Complexity** | Simpler for basic needs | More setup required |
|
|
75
|
+
|
|
76
|
+
## 3. Creating a TableView
|
|
77
|
+
|
|
78
|
+
### Basic TableView
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
const table = Ti.UI.createTableView({
|
|
82
|
+
height: Ti.UI.FILL,
|
|
83
|
+
width: Ti.UI.FILL,
|
|
84
|
+
backgroundColor: 'white',
|
|
85
|
+
rowHeight: 50,
|
|
86
|
+
separatorColor: '#ccc'
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
win.add(table);
|
|
90
|
+
```
|
|
91
|
+
...
|
|
92
|
+
## 4. Creating rows
|
|
93
|
+
|
|
94
|
+
### Object Literal Rows (Simple)
|
|
95
|
+
|
|
96
|
+
```javascript
|
|
97
|
+
const data = [
|
|
98
|
+
{ title: 'Row 1' },
|
|
99
|
+
{ title: 'Row 2' },
|
|
100
|
+
{ title: 'Row 3' }
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const table = Ti.UI.createTableView({
|
|
104
|
+
data: data
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
win.add(table);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Explicit TableViewRow Objects
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
const row = Ti.UI.createTableViewRow({
|
|
114
|
+
title: 'Row 1',
|
|
115
|
+
// Performance optimization
|
|
116
|
+
className: 'row'
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
table.appendRow(row);
|
|
120
|
+
|
|
121
|
+
// With explicit row, you can call methods
|
|
122
|
+
const imgCapture = row.toImage();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Performance: setData() vs appendRow()
|
|
126
|
+
|
|
127
|
+
```javascript
|
|
128
|
+
// GOOD - Batch assignment
|
|
129
|
+
const rows = [];
|
|
130
|
+
for (let i = 0; i < 100; i++) {
|
|
131
|
+
rows.push({ title: `Row ${i}` });
|
|
132
|
+
}
|
|
133
|
+
table.setData(rows); // Fast
|
|
134
|
+
|
|
135
|
+
// AVOID - Adding one by one (slow for many rows)
|
|
136
|
+
for (let i = 0; i < 100; i++) {
|
|
137
|
+
table.appendRow({ title: `Row ${i}` });
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Best Practice**: Use `setData()` for multiple rows. `appendRow()` is significantly slower.
|
|
142
|
+
|
|
143
|
+
## 5. Row Properties
|
|
144
|
+
|
|
145
|
+
### Built-in Row Properties
|
|
146
|
+
|
|
147
|
+
| Property | Description |
|
|
148
|
+
| ----------------- | --------------------------------- |
|
|
149
|
+
| `title` | Row title text |
|
|
150
|
+
| `className` | Reuse identifier for performance |
|
|
151
|
+
| `leftImage` | Image to left of title |
|
|
152
|
+
| `rightImage` | Image to right of title |
|
|
153
|
+
| `backgroundImage` | Row background image |
|
|
154
|
+
| `backgroundColor` | Row background color |
|
|
155
|
+
| `hasChild` | Shows > indicator (iOS/Android) |
|
|
156
|
+
| `hasDetail` | Shows detail indicator (iOS only) |
|
|
157
|
+
| `hasCheck` | Shows checkmark indicator |
|
|
158
|
+
| `header` | Section header text |
|
|
159
|
+
| `footer` | Section footer text |
|
|
160
|
+
|
|
161
|
+
### Styled Rows Example
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
const data = [
|
|
165
|
+
{ title: 'Row 1', leftImage: 'icon.png', hasChild: true },
|
|
166
|
+
{ title: 'Row 2', rightImage: 'arrow.png', hasDetail: true },
|
|
167
|
+
{ title: 'Row 3', backgroundColor: '#fdd', hasCheck: true }
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
const table = Ti.UI.createTableView({ data: data });
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Row Indicators
|
|
174
|
+
|
|
175
|
+
Row indicators provide visual cues:
|
|
176
|
+
|
|
177
|
+
```javascript
|
|
178
|
+
// iOS and Android
|
|
179
|
+
{ title: 'Sub-items', hasChild: true } // > arrow
|
|
180
|
+
|
|
181
|
+
// iOS only
|
|
182
|
+
{ title: 'Details', hasDetail: true } // circle with i
|
|
183
|
+
|
|
184
|
+
// Both platforms
|
|
185
|
+
{ title: 'Selected', hasCheck: true } // checkmark
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## 6. Custom Rows
|
|
189
|
+
|
|
190
|
+
### Adding Child Views
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
const data = [];
|
|
194
|
+
|
|
195
|
+
for (let i = 0; i < 10; i++) {
|
|
196
|
+
const row = Ti.UI.createTableViewRow({
|
|
197
|
+
height: 60,
|
|
198
|
+
className: 'customRow'
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const label = Ti.UI.createLabel({
|
|
202
|
+
left: 10,
|
|
203
|
+
text: `Row ${i + 1}`,
|
|
204
|
+
font: { fontSize: 16 }
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const image = Ti.UI.createImageView({
|
|
208
|
+
right: 10,
|
|
209
|
+
image: 'icon.png'
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const button = Ti.UI.createButton({
|
|
213
|
+
right: 60,
|
|
214
|
+
width: 80,
|
|
215
|
+
height: 30,
|
|
216
|
+
title: 'Action'
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
row.add(label);
|
|
220
|
+
row.add(image);
|
|
221
|
+
row.add(button);
|
|
222
|
+
|
|
223
|
+
data.push(row);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const table = Ti.UI.createTableView({ data: data });
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Performance Warning
|
|
230
|
+
|
|
231
|
+
**Warning**: Complex rows have performance implications. Each unique UI element adds resource requirements multiplied by the number of rows. Test on device and scale back if necessary.
|
|
232
|
+
|
|
233
|
+
## 7. Headers and Footers
|
|
234
|
+
|
|
235
|
+
### Table-Level Headers/Footers
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
const table = Ti.UI.createTableView({
|
|
239
|
+
data: data,
|
|
240
|
+
headerTitle: 'Table Header',
|
|
241
|
+
footerTitle: 'Table Footer'
|
|
242
|
+
});
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Custom Header/Footer Views
|
|
246
|
+
|
|
247
|
+
```javascript
|
|
248
|
+
function createCustomView(title) {
|
|
249
|
+
const view = Ti.UI.createView({
|
|
250
|
+
height: 40,
|
|
251
|
+
backgroundColor: '#222'
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const text = Ti.UI.createLabel({
|
|
255
|
+
left: 20,
|
|
256
|
+
text: title,
|
|
257
|
+
color: '#fff'
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
view.add(text);
|
|
261
|
+
return view;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const table = Ti.UI.createTableView({
|
|
265
|
+
data: data,
|
|
266
|
+
headerView: createCustomView('Header View'),
|
|
267
|
+
footerView: createCustomView('Footer View')
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Section Headers/Footers
|
|
272
|
+
|
|
273
|
+
```javascript
|
|
274
|
+
const data = [
|
|
275
|
+
{ title: 'Row 1', header: 'Section 1' },
|
|
276
|
+
{ title: 'Row 2' },
|
|
277
|
+
{ title: 'Row 3' },
|
|
278
|
+
{ title: 'Row 4', header: 'Section 2' },
|
|
279
|
+
{ title: 'Row 5' }
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
const table = Ti.UI.createTableView({ data: data });
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## 8. Grouped Table Style (iOS)
|
|
286
|
+
|
|
287
|
+
```javascript
|
|
288
|
+
const data = [
|
|
289
|
+
{ title: 'row 1', header: 'Header 1' },
|
|
290
|
+
{ title: 'row 2' },
|
|
291
|
+
{ title: 'row 3' },
|
|
292
|
+
{ title: 'row 4', header: 'Header 2' },
|
|
293
|
+
{ title: 'row 5' }
|
|
294
|
+
];
|
|
295
|
+
|
|
296
|
+
const table = Ti.UI.createTableView({
|
|
297
|
+
data: data,
|
|
298
|
+
style: Ti.UI.iPhone.TableViewStyle.GROUPED
|
|
299
|
+
});
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
## 9. Editing Mode
|
|
303
|
+
|
|
304
|
+
```javascript
|
|
305
|
+
table.editing = true;
|
|
306
|
+
|
|
307
|
+
// Allow row movement
|
|
308
|
+
table.moving = true;
|
|
309
|
+
|
|
310
|
+
// Allow deletion
|
|
311
|
+
const data = [
|
|
312
|
+
{ title: 'Row 1', canEdit: true },
|
|
313
|
+
{ title: 'Row 2', canEdit: false } // Cannot be deleted
|
|
314
|
+
];
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## 10. TableView Events
|
|
318
|
+
|
|
319
|
+
### Click Event
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
table.addEventListener('click', (e) => {
|
|
323
|
+
// e.index: row index
|
|
324
|
+
// e.row: TableViewRow object
|
|
325
|
+
// e.rowData: row data object
|
|
326
|
+
// e.section: section (if using sections)
|
|
327
|
+
|
|
328
|
+
Ti.API.info(`Clicked row: ${e.index}`);
|
|
329
|
+
Ti.API.info(`Row title: ${e.row.title}`);
|
|
330
|
+
});
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Delete Event
|
|
334
|
+
|
|
335
|
+
```javascript
|
|
336
|
+
table.addEventListener('delete', (e) => {
|
|
337
|
+
Ti.API.info(`Deleted row: ${e.row.title}`);
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Scroll Events
|
|
342
|
+
|
|
343
|
+
```javascript
|
|
344
|
+
table.addEventListener('scroll', (e) => {
|
|
345
|
+
Ti.API.info(`Scrolling... y=${e.y}`);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
table.addEventListener('scrollEnd', (e) => {
|
|
349
|
+
Ti.API.info(`Scroll ended at y=${e.y}`);
|
|
350
|
+
});
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## 11. Searching
|
|
354
|
+
|
|
355
|
+
```javascript
|
|
356
|
+
const search = Ti.UI.createSearchBar({
|
|
357
|
+
top: 0,
|
|
358
|
+
height: 43,
|
|
359
|
+
showCancel: true
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
const table = Ti.UI.createTableView({
|
|
363
|
+
search: search, // Attach search bar
|
|
364
|
+
searchHidden: false // Initially visible
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
## 12. Updating Table Data
|
|
369
|
+
|
|
370
|
+
### Appending Rows
|
|
371
|
+
|
|
372
|
+
```javascript
|
|
373
|
+
table.appendRow({ title: 'New Row' });
|
|
374
|
+
|
|
375
|
+
// Append multiple
|
|
376
|
+
table.appendRow([
|
|
377
|
+
{ title: 'Row 1' },
|
|
378
|
+
{ title: 'Row 2' }
|
|
379
|
+
]);
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Inserting Rows
|
|
383
|
+
|
|
384
|
+
```javascript
|
|
385
|
+
table.insertRowBefore(2, { title: 'Inserted at index 2' });
|
|
386
|
+
table.insertRowAfter(5, { title: 'Inserted after index 5' });
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Deleting Rows
|
|
390
|
+
|
|
391
|
+
```javascript
|
|
392
|
+
table.deleteRow(3); // Delete row at index 3
|
|
393
|
+
|
|
394
|
+
// Clear all rows
|
|
395
|
+
table.setData([]);
|
|
396
|
+
// NOT: table.data = null (causes issues)
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Updating Specific Row
|
|
400
|
+
|
|
401
|
+
```javascript
|
|
402
|
+
const data = table.data;
|
|
403
|
+
data[2].title = 'Updated Title';
|
|
404
|
+
table.setData(data);
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
## 13. TableView Sections
|
|
408
|
+
|
|
409
|
+
### Creating Sections
|
|
410
|
+
|
|
411
|
+
```javascript
|
|
412
|
+
const section1 = Ti.UI.createTableViewSection({
|
|
413
|
+
headerTitle: 'Section 1'
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
section1.add(Ti.UI.createTableViewRow({ title: 'Row 1' }));
|
|
417
|
+
section1.add(Ti.UI.createTableViewRow({ title: 'Row 2' }));
|
|
418
|
+
|
|
419
|
+
const section2 = Ti.UI.createTableViewSection({
|
|
420
|
+
headerTitle: 'Section 2',
|
|
421
|
+
footerTitle: 'Section Footer'
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
section2.add(Ti.UI.createTableViewRow({ title: 'Row 3' }));
|
|
425
|
+
|
|
426
|
+
const table = Ti.UI.createTableView({
|
|
427
|
+
data: [section1, section2]
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
### Custom Section Headers
|
|
432
|
+
|
|
433
|
+
```javascript
|
|
434
|
+
const section = Ti.UI.createTableViewSection({
|
|
435
|
+
headerView: createCustomView('Custom Header')
|
|
436
|
+
});
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## 14. Performance Optimization
|
|
440
|
+
|
|
441
|
+
### Use className
|
|
442
|
+
|
|
443
|
+
```javascript
|
|
444
|
+
// GOOD - Rows with same structure share className
|
|
445
|
+
const row1 = Ti.UI.createTableViewRow({
|
|
446
|
+
title: 'Row 1',
|
|
447
|
+
className: 'standardRow'
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
const row2 = Ti.UI.createTableViewRow({
|
|
451
|
+
title: 'Row 2',
|
|
452
|
+
// Reuses row1's template
|
|
453
|
+
className: 'standardRow'
|
|
454
|
+
});
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
`className` enables OS to reuse scrolled-out rows for faster rendering.
|
|
458
|
+
|
|
459
|
+
### Avoid Too Many Rows
|
|
460
|
+
|
|
461
|
+
If you have thousands of rows, consider:
|
|
462
|
+
- Pagination
|
|
463
|
+
- ListView instead
|
|
464
|
+
- Filtering mechanism
|
|
465
|
+
- Drill-down interface
|
|
466
|
+
|
|
467
|
+
### Optimize Custom Rows
|
|
468
|
+
|
|
469
|
+
- Test on device
|
|
470
|
+
- Use simple layouts
|
|
471
|
+
- Minimize child views per row
|
|
472
|
+
- Avoid nested ScrollViews
|
|
473
|
+
|
|
474
|
+
## 15. Common Patterns
|
|
475
|
+
|
|
476
|
+
### Detail View Navigation
|
|
477
|
+
|
|
478
|
+
```javascript
|
|
479
|
+
table.addEventListener('click', (e) => {
|
|
480
|
+
const detailWin = Ti.UI.createWindow({
|
|
481
|
+
title: e.row.title,
|
|
482
|
+
backgroundColor: 'white'
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
const detailLabel = Ti.UI.createLabel({
|
|
486
|
+
text: `Details for ${e.row.title}`
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
detailWin.add(detailLabel);
|
|
490
|
+
detailWin.open();
|
|
491
|
+
});
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### Row Actions (Swipe to Delete)
|
|
495
|
+
|
|
496
|
+
```javascript
|
|
497
|
+
table.setEditable(true);
|
|
498
|
+
|
|
499
|
+
table.addEventListener('delete', (e) => {
|
|
500
|
+
// Confirm deletion
|
|
501
|
+
const dialog = Ti.UI.createAlertDialog({
|
|
502
|
+
title: 'Delete',
|
|
503
|
+
message: 'Delete this row?',
|
|
504
|
+
buttonNames: ['Delete', 'Cancel']
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
dialog.addEventListener('click', (evt) => {
|
|
508
|
+
if (evt.index === 0) {
|
|
509
|
+
// Delete confirmed
|
|
510
|
+
// e.row is automatically removed
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
dialog.show();
|
|
515
|
+
});
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Refresh Control
|
|
519
|
+
|
|
520
|
+
```javascript
|
|
521
|
+
const table = Ti.UI.createTableView({
|
|
522
|
+
refreshControl: Ti.UI.createRefreshControl({
|
|
523
|
+
tintColor: 'blue'
|
|
524
|
+
})
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
table.refreshControl.addEventListener('refreshstart', () => {
|
|
528
|
+
// Load data
|
|
529
|
+
loadData(() => {
|
|
530
|
+
table.refreshControl.endRefreshing();
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
## 16. Platform Differences
|
|
536
|
+
|
|
537
|
+
### iOS
|
|
538
|
+
- Supports `GROUPED` style
|
|
539
|
+
- Supports `hasDetail` indicator
|
|
540
|
+
- Modal windows fill screen
|
|
541
|
+
- NavigationController integration
|
|
542
|
+
|
|
543
|
+
### Android
|
|
544
|
+
- No `GROUPED` style
|
|
545
|
+
- `hasDetail` not supported
|
|
546
|
+
- Windows always fill screen
|
|
547
|
+
- Back button closes windows
|
|
548
|
+
|
|
549
|
+
## 17. Migration: TableView to ListView
|
|
550
|
+
|
|
551
|
+
When to migrate:
|
|
552
|
+
- New app development
|
|
553
|
+
- Large datasets (>100 rows)
|
|
554
|
+
- Performance issues
|
|
555
|
+
- Need modern features (templates, binding)
|
|
556
|
+
|
|
557
|
+
Key differences:
|
|
558
|
+
- TableView: `data` property with row objects
|
|
559
|
+
- ListView: `sections` property with templates
|
|
560
|
+
|
|
561
|
+
## Best Practices
|
|
562
|
+
|
|
563
|
+
1. **Use ListView for new apps** - Better performance and features
|
|
564
|
+
2. **Use className** - Enables row reuse
|
|
565
|
+
3. **Batch updates** - Use `setData()` instead of multiple `appendRow()`
|
|
566
|
+
4. **Test on device** - Simulator performance differs
|
|
567
|
+
5. **Limit row complexity** - Fewer children = better scrolling
|
|
568
|
+
6. **Consider pagination** - Don't show thousands of rows at once
|