i'm trying to add a "view more rows" from an sqlite db - i had working code when i pulled from an online mysql (via json) so ive tried to amend it
i've got so far that i get the view more but clicking seems to get the next 8 records but only shows the last 2 added rows in the tableview and doesnt add another view more at the end - ive looked at this code all day and i'm obviously got too far into a mix & match code and cant see where i'm going wrong
var win = Ti.UI.currentWindow; var page = 1; var page_size = 8; var more_index = 0; var categoryArray = []; var tableView = Ti.UI.createTableView({ top:0, left:0, right:0, zIndex:10, backgroundColor:'transparent', separatorColor:'#ccc' }); win.add(tableView); function addRow(buses){ Ti.API.info('Adding row for : '+buses.direction); var row = Ti.UI.createTableViewRow({height:'auto',hasChild:false,selectedBackgroundColor:'#4eaaf0'}); var title_label = Ti.UI.createLabel({ text:buses.direction, left:4, top:4, height:'auto', font:{fontFamily:'Helvetica Neue',fontSize:16,fontWeight:'bold'}, color:'#fff', right:0, textAlign:'left', touchEnabled:false }); row.add(title_label); row.id = buses.id; row.className = 'buses'; tableView.appendRow(row); } function getBuses(page){ var db = Titanium.Database.open('bus'); var dbrows = db.execute('select * FROM bus LIMIT 0,'+page_size); while (dbrows.isValidRow()) { categoryArray.push({ id:dbrows.fieldByName('id'), direction:dbrows.fieldByName('direction'), }); dbrows.next(); } dbrows.close(); db.close(); var buses = categoryArray; Ti.API.info(buses); Ti.API.info('there are '+buses.length); for(var i in buses){ if(i){ addRow(buses[i]); } Ti.API.info('i: '+i); if(i == page_size-1){ var more_row = Ti.UI.createTableViewRow({height:'auto',hasChild:true,selectedBackgroundColor:'#4eaaf0'}); var title_label = Ti.UI.createLabel({ text:'View more ... ', left:10, top:12, height:20, font:{fontFamily:'Helvetica Neue',fontSize:16,fontWeight:'normal'}, color:'#fff', right:0, textAlign:'left', touchEnabled:false }); more_row.add(title_label); more_row.id = 'MORE'; tableView.appendRow(more_row); } if(page > 0 && more_index!=0){ tableView.deleteRow(more_index); } }; } tableView.addEventListener('click',function(e){ Ti.API.info('You clicked the tableView : '+e.rowData.id); if(e.rowData.id=='MORE'){ more_index = e.index; page_size+=8; getBuses(page); } else { //link to stuff.... } }); getBuses(page);
Your Answer
Think you can help? Login to answer this question!