我正在使用Datatables JQuery插件,并希望执行以下操作:
我有一组数据,假设有 350 条记录。 无论大小如何,我都想以 3 个偶数批次(或尽可能均匀)提取记录,并将它们显示在一页上的 3 个表格中。 不应有分页。 我想在一个桌子上排序,对其他表进行排序。
我尝试根据数据库中的记录数动态生成表,然后创建一个for loop
。 并且显示由 MySQL 中的 LIMIT
参数控制。 问题是,如果表 2 应该显示记录 51 - 100,我能够完成此操作,但它仍然将其显示为数据子集:例如,如果我点击"按名称排序",它会参考其他 200 条记录进行排序,而不是在分配的 50 条记录内。
有没有更简单的方法可以做到这一点? 这是我尝试过的:
jQuery.getJSON( templateDir + "/include/_shelf_record_check.php", function( data ) { 货架总记录 = 数据.总计;
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" }
]
});
});
}
首先执行 for 循环,将数据拆分为 3 个不同的数组,然后将这些单独的源传递给 jQuery。 还是我错过了什么?否则,如果您可以存储第一个结果的"ID",然后在每个查询上发送这些 ID,.
我相信我使用"fnServerParams"参数解决了这个问题,该参数允许您将数据传递到 Ajax 源,以便进一步过滤