I am working in chrome extension, I want to make paging for table which is fill dynamically using sqlite queries.
I am using this tutorial to make the paging and make some modification in init function
http://en.newinstance.it/2006/09/27/client-side-html-table-pagination-with-javascript/
When I want to get the length of the table after filling it, the dom seems to be not ready and the result return as ZERO of table length, here’s some of my code..
function ViewAllNotes(db){
var allListItems;
var cur = fromDateToString(new Date(),"date");
db.transaction(function(tx) {
tx.executeSql("SELECT NOTE_DESC,NOTE_DATE,NOTE_TIME FROM NOTES where NOTE_DATE = ? order by NOTE_TIME desc ",[cur],function(tx,result){
alert(result.rows.length);
for(i=0;i< result.rows.length;i++){
tr= "<tr>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_DESC']+"</td>";
tr=tr+ "<td>"+ result.rows.item(i)['NOTE_TIME']+"</td>";
tr=tr+ "</tr>";
allListItems+=tr;
}
var tableContent= " <thead><tr><th id='activityHeader'>Activity</th> <th>Time</th></tr></thead>";
tableContent = tableContent+"<tbody>"+allListItems+"</tbody>";
$("table#notes").append(tableContent);
//$('#notes').dataTable();
},onError);
});
}
EDIT
At the begining of the js file I make like this
ViewAllNotes(db);
var rows = document.getElementById("notes").rows;
alert("rows "+rows.length);
then call the pager class, but also it alerts with zero ?
SQL calls are aysynchronous. Your code that tests for length will not have a length available until the SQL finishes and fires the callback.