-
-
Save nuno/be6c5f046ddbde6cb8e3 to your computer and use it in GitHub Desktop.
Expendable row
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Hello, I have tested this issue in Ti SDK 3.3.0.RC. Its working good. | |
| Testing Environment: | |
| Titanium SDK: 3.3.0.RC, 3.2.3.GA | |
| Titanium CLI: 3.2.3 | |
| IOS Simulator 7.1 | |
| Appcelerator Studio, build: 3.3.0.201406271159 | |
| */ | |
| var win = Titanium.UI.createWindow({ | |
| title : 'Expandable Row', | |
| layout : 'vertical', | |
| backgroundColor : '#000' | |
| }); | |
| var container = Ti.UI.createView({backgroundColor: "white", layout: "vertical"}); | |
| var layout = [ | |
| { | |
| title: "Parent 1", | |
| isparent: true, | |
| opened: false, | |
| sub: [ | |
| { | |
| title: "Child 3", | |
| color:'red', | |
| }, | |
| { | |
| title: "Child 2", | |
| color:'red' | |
| }, | |
| { | |
| title: "Child 1", | |
| color:'red' | |
| } | |
| ] | |
| }, | |
| { | |
| title: "Parent 2", | |
| isparent: true, | |
| opened: false, | |
| sub: [ | |
| { | |
| title: "Child 6", | |
| color:'green' | |
| }, | |
| { | |
| title: "Child 5", | |
| color:'green' | |
| }, | |
| { | |
| title: "Child 4", | |
| color:'green' | |
| } | |
| ] | |
| }, | |
| { | |
| title: "Parent 3", | |
| isparent: true, | |
| opened: false, | |
| sub: [ | |
| { | |
| title: "Child 9", | |
| color:'blue' | |
| }, | |
| { | |
| title: "Child 8", | |
| color:'blue' | |
| }, | |
| { | |
| title: "Child 7", | |
| color:'blue' | |
| } | |
| ] | |
| } | |
| ]; | |
| var tableView = Ti.UI.createTableView({ | |
| style:Titanium.UI.iPhone.TableViewStyle.GROUPED, | |
| top: 0, | |
| height: Ti.Platform.displayCaps.platformHeight, | |
| data: layout | |
| }); | |
| tableView.addEventListener("click", function(e) { | |
| //Is this a parent cell? | |
| if(e.row.isparent) { | |
| //Is it opened? | |
| if(e.row.opened) { | |
| for(var i=e.row.sub.length; i > 0; i = i - 1) { | |
| tableView.deleteRow(e.index + i); | |
| } | |
| e.row.opened = false; | |
| } | |
| else { | |
| //Add teh children. | |
| var currentIndex = e.index; | |
| for(var i=0; i < e.row.sub.length; i++) { | |
| tableView.insertRowAfter(currentIndex, e.row.sub[i]); | |
| //currentIndex++; | |
| } | |
| e.row.opened = true; | |
| } | |
| } | |
| }); | |
| container.add(tableView); | |
| win.add(container); | |
| win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment