Skip to content

Instantly share code, notes, and snippets.

@minhnc
Created February 15, 2012 00:31
Show Gist options
  • Save minhnc/1832046 to your computer and use it in GitHub Desktop.
Save minhnc/1832046 to your computer and use it in GitHub Desktop.
app.js
function populateData() {
var currentWin = Ti.UI.createWindow();
var table = Ti.UI.createTableView();
var tableData = [];
// Init some data
var db = Titanium.Database.open('fullsched');
db.execute('CREATE TABLE IF NOT EXISTS events (title TEXT, start_dt TEXT, hasChild INTEGER)');
for (var i = 0; i < 10; i++) {
db.execute('INSERT INTO events (title, start_dt, hasChild) VALUES (?, ?, ?)', 'Title ' + i, 'start_dt ' + i, (i%2 == 0) ? 0 : 1);
}
var rows = db.execute('SELECT title, start_dt, hasChild FROM events');
while (rows.isValidRow())
{
var row = Titanium.UI.createTableViewRow({
height : '60dp',
backgroundColor : '#ffffff',
hasChild : true,
path : 'sessDet.js'
});
var nameLabel = Ti.UI.createLabel({
text : rows.fieldByName('title'),
font : {
fontSize : '15dp',
fontWeight : 'bold'
},
});
var start = Ti.UI.createLabel({
text : rows.fieldByName('start_dt'),
font : {
fontSize : '16dp'
},
height : 'auto',
left : '15dp',
bottom : '5dp',
color : '#000',
});
row.add(nameLabel);
row.add(start);
row.hasChild = rows.fieldByName('hasChild');
row.className = 'event_row';// Should have className for better performance
tableData.push(row);
rows.next();
}
rows.close();
db.close();
table.setData(tableData);
currentWin.add(table);
currentWin.open();
};
// In some place
populateData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment