Skip to content

Instantly share code, notes, and snippets.

@iskugor
Created April 30, 2012 14:15
Show Gist options
  • Save iskugor/2558686 to your computer and use it in GitHub Desktop.
Save iskugor/2558686 to your computer and use it in GitHub Desktop.
How to append a row to particular section in Titanium
(function() {
var win = Ti.UI.createWindow();
var section1 = Ti.UI.createTableViewSection({
headerTitle:'Header 1'
});
for (var i=0; i < 4; i++) {
section1.add(Ti.UI.createTableViewRow({
title:'Row '+i
}));
}
var section2 = Ti.UI.createTableViewSection({
headerTitle:'Header 2'
});
for (i=4; i < 10; i++) {
section2.add(Ti.UI.createTableViewRow({
title:'Row '+i
}));
}
var tv = Ti.UI.createTableView({
data:[section1,section2]
});
function appendRowToSection(tableView, row, sectionIndex) {
var sections = tableView.data;
if (!sections || sections.length < sectionIndex || isNaN(+sectionIndex)) {
return;
}
sections[sectionIndex].add(row);
tableView.setData(sections);
}
win.add(tv);
tv.addEventListener("click", function() {
appendRowToSection(tv, Ti.UI.createTableViewRow({ title: "new row"}), 0);
});
win.open();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment