数据表分页仅适用于第一个分页

时间:2017-05-29 05:42:04

标签: php jquery datatable datatables-1.10 jquery-pagination

我正在尝试使用数据表插件对数据进行分页,但其分页仅适用于第一次。首先,当我点击它工作的第二页时,它的负载显示数据但在此之后,它没有。它显示了表格顶部的处理,这是我的代码。

HTML

<table id="data_table" class="display" width="100%" cellspacing="0">
    <thead>
       <tr>
            <th><input type="checkbox" id="selectAll"/></th>
            <th>Plan Name</th>
            <th>Description</th>
            <th>Image</th>
            <th>Quantity</th>
            <th>Amount</th>
            <th>Action</th>
       </tr>
    </thead>
    <tbody></tbody>
</table>

JQUERY

$("#data_table").dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "bPaginate": true,
    "sAjaxSource": "response.php",
});

PHP

if(isset($_GET['iDisplayStart']))
    {
        $start = $_GET['iDisplayStart'];
    }
    else
    {
        $start = 0;
    }

    if(isset($_GET['iDisplayLength']))
    {
        $limit = $_GET['iDisplayLength'];
    }
    else
    {
        $limit = 10;
    }

    $plan = new Plan();
    $result = $plan->getPlanList($limit, $start);
    $count= $plan->getCountPlanList();
    $myarray['recordsTotal'] =  $count[0]['count(*)'];
    $myarray['recordsFiltered'] =  $count[0]['count(*)'];
    $myarray['draw']  = intval($start/$limit)+1;
    $myarray['data']  ="";
    foreach($result as $data)
    {
        $myarray['data'][] = array('<input type="checkbox" name="selectcheck[]" class="selectcheck" value="'.$data['id'].'">',$data['name'],$data['description'],$data['image'],$data['quantity'],$data['amount'],'<a href="">Edit</a>');
    }

    echo json_encode($myarray);
    die;

1 个答案:

答案 0 :(得分:1)

问题解决了。我在服务器端使用sEcho值进行绘制

  $myarray['draw']  = $_GET['sEcho'];