hi there, i have tableview which is loading new data while pulling down. Everything just fine it works but i want to make it total data === table.rowCount alert and i am not sure that setTimeOut function is ok? is there anyway to make it if the new data loaded delete the loadingrow? this is the kitchensink dynamic scrolling tableview example which is pulling data from a json file.
here is my code:
var win = Ti.UI.currentWindow; var limitstart = 0; var tbl_data = []; var lastRow = 10; var total_records = null; var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { var jsonObject = JSON.parse(this.responseText); total_records = jsonObject.total; Ti.API.info("Total Records:"+total_records) for (var i = limitstart; i < lastRow ; i++){ var row = Ti.UI.createTableViewRow({ backgroundColor:'#494949', className:'myClass', height:50 }); var label = Ti.UI.createLabel({ text:i+"-Ba?l?k:"+jsonObject.sorgu[i].baslik, left:20, font:{ size:10 }, color:'#FFF', top:0, width:280, height:45 }); row.add(label); tbl_data.push(row); } table.setData(tbl_data); }, xhr.onerror = function(){ alert("hata var"); } xhr.open("GET","http://www.mydomain.com/video.asp?limitstart="+limitstart+"&limitend="+lastRow+"&type="+19+""); xhr.send(); var table = Titanium.UI.createTableView({ data:tbl_data }); win.add(table); /// Second Part var navActInd = Titanium.UI.createActivityIndicator({ left:0, }); //win.setRightNavButton(navActInd); var updating = false; var loadingRow = Ti.UI.createTableViewRow({title:"Loading...",height:50}); loadingRow.add(navActInd); function beginUpdate() { Ti.API.info("Total Records Begin Update:"+total_records); //Here is the problem i can't get the row count? //i want to say if total data = row count do nothing just alert Ti.API.info("Total Record Table Data:"+table.data.rowCount); if(total_records === tbl_data.length){ alert("All Data Loaded"); }else{ updating = true; navActInd.show(); table.appendRow(loadingRow); // just mock out the reload setTimeout(endUpdate,5000); } } function endUpdate() { Ti.API.info("Total Records End Update:"+total_records); updating = false; table.deleteRow(lastRow,{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.NONE}); // simulate loading var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function() { var jsonObject = JSON.parse(this.responseText); for (var c=lastRow;c<lastRow+10;c++) { var row = Ti.UI.createTableViewRow({ backgroundColor:'#494949', className:'myClass', height:50 }); var label = Ti.UI.createLabel({ text:c+"-Ba?l?k:"+jsonObject.sorgu[c].baslik, left:20, font:{ size:10 }, color:'#FFF', top:0, width:280, height:45 }); row.add(label); table.appendRow(row); //table.appendRow({title:jsonObject.sorgu[c].baslik},{animationStyle:Titanium.UI.iPhone.RowAnimationStyle.NONE}); } lastRow += 10; // just scroll down a bit to the new rows to bring them into view table.scrollToIndex(lastRow-9,{animated:true,position:Ti.UI.iPhone.TableViewScrollPosition.BOTTOM}); navActInd.hide(); } xhr.open("GET","http://www.mydomain.com/video.asp?limitstart="+lastRow+"&limitend="+lastRow+10+"&type="+19+""); xhr.send(); } var lastDistance = 0; // calculate location to determine direction table.addEventListener('scroll',function(e) { var offset = e.contentOffset.y; var height = e.size.height; var total = offset + height; var theEnd = e.contentSize.height; var distance = theEnd - total; // going down is the only time we dynamically load, // going up we can safely ignore -- note here that // the values will be negative so we do the opposite if (distance < lastDistance) { // adjust the % of rows scrolled before we decide to start fetching var nearEnd = theEnd * .75; if (!updating && (total >= nearEnd)) { beginUpdate(); } } lastDistance = distance; });
1 Answer
Accepted Answer
table.section[0].rows.length this is the total number of rows in the table
Your Answer
Think you can help? Login to answer this question!