The original ajaxProcessing
option required that you returned:
- total rows (required),
- rows; within an array of arrays
- optional header cell text
in this strict format:
// [ total_rows (number), rows (array of arrays), headers (array; optional) ]
return [
100, // total rows
[
[ "row1cell1", "row1cell2", ... "row1cellN" ],
[ "row2cell1", "row2cell2", ... "row2cellN" ],
...
[ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
],
[ "header1", "header2", ... "headerN" ] // optional
]
Now, the rows can be returned as a jQuery object of the rows, which the addon then adds and updates (this is just an example):
var i, j, rows = '';
for (i = 0; i < data.rows.length; i++) {
rows += '<tr>';
for (j = 0; j < data.rows[i].cells.length; j++) {
rows += '<td>' + data.rows[i].cells[j] + '</td>';
}
rows += '</tr>';
}
// [ total rows, $rows (jQuery object; optional), headers (optional) ]
return [ data.total, $(rows), data.headers ];
Lastly, you can add the rows yourself and just return the total rows:
var i, j, rows = '';
for (i = 0; i < data.rows.length; i++) {
rows += '<tr>';
for (j = 0; j < data.rows[i].cells.length; j++) {
rows += '<td>' + data.rows[i].cells[j] + '</td>';
}
rows += '</tr>';
}
$('#mytable').find('tbody').html( rows );
// [ total rows, headers (optional) ]
return [ data.total ];
Similar examples of the above are also included in the documentation of the ajaxProcessing
option
So, to answer your questions
does the ajaxUrl still need to return JSON information for the set of rows or should it return the HTML for the table? If the JSON information is to be returned, how is the table input into the jQuery?
the ajaxUrl
option doesn't need to return anything. It is merely used as a method to get the next set of data by sending the appropriate page number, filter queries and column sort directions to the server. It shouldn't be returning any HTML. The pager addon will update the table after it has been processed.
How is the $rows object created? In general how should the code be changed to effect these different options?
Hopefully the example I shared above answers that question. But as stated, the above code is just an example as the ajax returned can be in pretty much any format. It is just no longer required that you have to build the array of arrays to return to the pager addon.
what determines which is the best choice of these options?
The best choice is left to you. The pager addon was written to give you more choices as to how you want to apply the ajax data. You could actually completely bypass the pager plugin and do the ajax processing yourself, then just update the pager. That's what makes the system flexible and hopefully work in many different situations.
In answer to your continuation try using this as your ajaxUrl
string:
databasequery.php?offset={page}&numrows={size}
If numrows
is fixed at 25 rows, then you can remove the {size}
, as I would guess your server side script would always return at most 25 rows worth of data:
databasequery.php?offset={page}