2017-05-29 74 views
1

我想分页我的数据与数据表插件,但它的分页仅适用于第一次。首先,它的负载显示数据,当我点击它的第二页时,但在那之后,它不会。它显示了表格顶部的处理是我的代码。datatable分页工作只为第一个分页

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

在控制台上没有收到任何错误。在控制台上它发送请求到服务器并获取数据,但数据没有绘制 –

+0

您必须添加'“pagingType”:“full_numbers”' –

回答

1

问题就迎刃而解了。我使用sEcho值在服务器端绘制

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