2016-07-05 132 views
3

我想在一個php項目上使用服務器端處理實現jquery datatables,但分頁不起作用,我在螢火蟲控制檯中沒有錯誤。jquery datatable服務器端分頁不起作用

的頁面是簡單和直接的,這裏是html代碼:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 

    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.css"/> 
    <script type="text/javascript" src="https://cdn.datatables.net/v/dt/jq-2.2.3/dt-1.10.12/datatables.min.js"></script> 

</head> 

<body> 
<table class="table"> 
    <thead> 
    <tr> 
    <th col-data="item_id">Item Id</th> 
    <th col-data="name">Name</th> 
    </tr> 
    </thead> 
</table> 

<script type="text/javascript"> 

    $(document).ready(function() { 
    var dataTable = $('.table').DataTable({ 
     "processing": true, 
     "serverSide": true, 
     "buttons": [], 
     "order": [], 
     "ajax":{ 
     url :"{{ url('stock_acc_get') }}", // json datasource 
     type: "post", 
     } 
    }); 

    }); 
</script> 

</body> 

</html> 

這是貼在服務器上的數據(在Firebug控制檯查看):

columns[0][data]  0 
columns[0][name]  
columns[0][orderable]  true 
columns[0][search][regex] false 
columns[0][search][value] 
columns[0][searchable]  true 
columns[1][data]  1 
columns[1][name]  
columns[1][orderable]  true 
columns[1][search][regex] false 
columns[1][search][value] 
columns[1][searchable]  true 
draw 1 
length 10 
search[regex] false 
search[value] 
start 0 

這裏是從服務器JSON響應:

{ 
    "draw":1, 
    "recordsTotal":23, 
    "recordsFiltered":10, 
    "data": [ 
    ["100018","Test Acc"],["100019","Test Acc 2"], 
    ["100020","Test Acc 3"],["5845645","Optional 1"], 
    ["56456456","Optional 2"],["541515","Optional 3"], 
    ["845812","Optional 4"],["103646","Belte Setesdal"], 
    ["103647","Belte Setesdal"],["103681","Belte Sigdal-Eggedal"] 
    ] 
} 

的頁被設置爲顯示10條記錄。 記錄總數爲23,並且不會創建鏈接以導航到下一頁。爲了更好理解,我附上了一張照片,Next/Previous按鈕被禁用,它顯示我只有一頁。

enter image description here

回答

6

recordsFiltered應該代表的是通過搜索框過濾器,頁面上沒有記錄的數量(與其他一起)的記錄數。

你告訴的數據表,目前只有10個相關記錄,所以它不會試圖建立對其他13

傳呼看第三數據表FAQ post(在服務器端處理類) ,或鏈接在該帖子中的Server-side processing頁面以獲取更多信息。

+0

鏈接到'常見問題'是真的很有幫助。 –

0

主要是recordsFiltered正在創建分頁。所以通過這個參數在您的表中的數據總數recordsFiltered