【问题标题】:Datatables - Data set across 3 tables evenly - single controls数据表 - 均匀分布在 3 个表中的数据集 - 单个控件
【发布时间】:2013-10-14 18:36:19
【问题描述】:

我正在使用 Datatables JQuery 插件并希望执行以下操作:

我有一组数据,比如说 350 条记录。无论大小如何,我都想将记录分成 3 个均匀批次(或尽可能均匀),并将它们显示在 3 个表中,在一页上。不应该有分页。我想在一张桌子上进行排序,以对其他桌子进行排序。

我尝试过根据数据库中的记录数动态生成表,然后创建for loop。并且显示是由 MySQL 中的LIMIT 参数控制的。问题是,如果表 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" }
         ]

      });
   });
}

【问题讨论】:

    标签: php jquery mysql datatable


    【解决方案1】:

    首先执行 for 循环将数据拆分为 3 个不同的数组,然后将这些单独的源传递给 jquery。还是我错过了什么?否则,如果您可以存储第一个结果的“id”,然后在每个查询中发送这些 id。

    【讨论】:

    • 我尝试了后一种建议,但无论出于何种原因,每次查询都无法发送它们。我试图在 URL 中将返回的 JSON 对象发送到 _get_shelf_table.php 脚本,但我认为它的格式可能不正确,因为它似乎永远不会到达 PHP 脚本
    • 我不知道你的 api 但也许每个表的记录不是正确的方法。它应该类似于“endrecord”
    • 我不认为 Datatables 具有“endrecord”之类的功能,但我会仔细检查
    【解决方案2】:

    我相信我使用“fnServerParams”参数解决了这个问题,它允许您将数据传递到 Ajax 源,以便进一步过滤

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-16
      • 1970-01-01
      • 2011-12-05
      • 2013-11-11
      • 2018-02-06
      • 2015-01-18
      相关资源
      最近更新 更多