Ajax sourced dataTable没有对数据进行排序,搜索或分页。 由于iTotalRecords',它在页脚中显示5页,但所有数据实际显示在一页中。
JSON:{"sEcho":"1","iTotalRecords":44,"iTotalDisplayRecords":44,"aaData":[{"one":"--qqqq","two":"--yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"----qqqq","two":"----yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"qqqq","two":"yyyy"},{"one":"tttttt","two":"iiiiii"},{"one":"tttttt","two":"iiiiii"}]}
`
$(document).ready(function () {
$("#testtable").dataTable({
"bProcessing": true,
"sAjaxSource": '/api/test',
"sAjaxDataProp": "aaData",
"bServerSide": true,
"aoColumns": [
{ "mData": "one", "sType": "text", "bSortable": true, "bUseRendered": false },
],
});
});
</script>
<table id="testtable">
<thead>
<tr>
<th>one1</th>
</tr>
</thead>
</table>
`
答案 0 :(得分:0)
感谢charlietfl,我找到了正确的设置。
$(document).ready(function () {
$("#testtable").dataTable({
"ajax":'/api/test',
"columns": [
{"data":"one"}
]
});
});
我尝试了类似的设置,但没有“columns”属性。 在dataTable官方示例中,他们有一个非常相似的ajax数据和表,他们的示例不包括“列”,但他们的例子不同。