我使用DataTable通過serverSide模式和ajax顯示我的數據。
一切都還好,但分頁不起作用。DataTable分頁不起作用
您可以查看代碼如下:
HTML:
<table id="table" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<td>ID</td>
<td>First name</td>
<td>Last name</td>
<td>Email</td>
</tr>
</thead>
<tbody></tbody>
</table>
的Javascript:
$(document).ready(function() {
$('#table').DataTable({
serverSide: true,
ajax: {
url: '<?php echo base_url(); ?>folder/class/method'
},
processing: true,
scrollY: 370,
paging: true,
bJQueryUI: true
});
});
,從服務器(JSON
)返回如下數據:
{
"draw": 1,
"recordsTotal": 1208,
"recordsFiltered": 10,
"data": [
["1", "pando", "rewar", "[email protected]"],
["2", "chori", "raon", "[email protected]"],
["3", "Gorbat", "horiz", "[email protected]"],
["4", "martin", "sokza", "[email protected]"],
["5", "dooz", "solda", "[email protected]"],
["6", "maro", "meza", "[email protected]"],
["7", "nod", "ion", "[email protected]"],
["8", "kaz", "loob", "[email protected]"],
["9", "Barbara", "Elliott", "[email protected]"],
["10", "Kendall", "Nathaniel", "[email protected]"]
]
}
DataTable的所有組件都正常工作,但分頁沒有。
我猜測它與你有關,使用該頂部下拉菜單將結果設置爲25。它的底部顯示25個條目中的25個,從1208中過濾出來。它應該顯示120箇中的25個。 – Mike
@Mike:很好,但現在的問題是'recordsTotal'和'recordsFiltered'從中獲取數據同一來源。我認爲'recordsTotal' =表中的所有行(例如:1208)和'recordsFiltered' =一次顯示的數據(例如:25)。但現在我改變了相同的來源(例如:1208)。 –