我正在使用 Datatables JQuery 插件,并希望执行以下操作:
我有一组数据,比如说 350 条记录。无论大小如何,我都想将记录分成 3 个均匀批次(或尽可能均匀),并将它们显示在 3 个表中,在一页上。不应该有分页。我想在一张桌子上进行排序,以对其他桌子进行排序。
我尝试根据数据库中的记录数动态生成表,然后创建一个for loop
. 并且显示是由LIMIT
MySQL 中的参数控制的。问题是,如果表 2 应该显示记录 51 - 100,我能够做到这一点,但它仍然将其显示为数据的子集:例如,如果我点击“按名称排序”,它会排序参考其他 200 条记录,而不是在分配的 50 条中。
是否有更简单的方法可以做到这一点?这是我尝试过的:
jQuery.getJSON(templateDir + "/includes/_shelf_record_check.php", function(data) {shelfTotalRecords = data.total;
var recordsPerTable = 40;
var numberOfTables = Math.ceil(shelfTotalRecords / recordsPerTable);
for(var i=1; i<=numberOfTables; i++) {
if (i == 1)
var startRecord = 0;
else
var startRecord = ((i-1) * recordsPerTable);
jQuery.getJSON( templateDir + "/includes/_records_for_shelf_table.php?startRecord="+startRecord+"&recordsPerTable="+recordsPerTable, function( recordData ) {
var shelfTable = "shelfTable"+i;
var HTMLTableID = 'shelf-table'+i;
jQuery('#shelf-table-page').append("<table id='"+HTMLTableID+"' class='display dataTable shelf'>" +
"<thead>" +
"<tr>"+
"<th></th>"+
"<th>Order</th>"+
"<th>First Name</th>"+
"<th>Last Name</th>"+
"<th>Shelf</th>"+
"<th>Status</th>"+
"</tr>"+
"</thead>"+
"<tbody>"+
"<tr>"+
"<td colspan='4' class='dataTables_empty'>Loading data from server</td>"+
"</tr>" +
"</tbody>"+
"<tfoot>"+
"<tr>"+
"<th></th>"+
"<th>Order</th>"+
"<th>First Name</th>"+
"<th>Last Name</th>"+
"<th>Shelf</th>"+
"<th>Status</th>"+
"</tr>"+
"</tfoot>" +
"</table>");
/* DataTable for the Shelf Table Page */
shelfTable = jQuery('#'+HTMLTableID).dataTable( {
"bPaginate": false,
"iDisplayLength": recordsPerTable,
"iDisplayStart": startRecord,
"bProcessing": true,
"bServerSide": true,
"bDestroy": true,
"bJQueryUI": true,
"bFilter": false,
"bAutoWidth": false,
"oLanguage": {
"sInfoFiltered": " (_MAX_ total records)"
},
"bLengthChange": false,
"sAjaxSource": templateDir + "/includes/_get_shelf_table.php?recordIds="+recordData.recordIds,
"aaSorting": [[ 3, "asc" ]],
"aoColumns": [
{ "sName": "id", "bVisible": false },
{ "sName": "order_number"},
{ "sName": "first_name"},
{ "sName": "last_name"},
{ "sName": "shelf" },
{ "sName": "status_id" }
]
});
});
}