仅首先分页的数据表分页工作



我试图使用数据表插件分页我的数据,但其分页仅首次起作用。首先,当我单击第二页时,其负载显示数据,但此后却没有。它在表的顶部显示处理是我的代码。

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;

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

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

最新更新