当我尝试从服务器端脚本
获取数据时,我收到以下错误DataTables警告:table id = example - 请求的未知参数' 0' 对于第0行。有关此错误的详细信息,请参阅 http://datatables.net/tn/4
我做错了什么?
这是HTML
<script>
$(document).ready(function(){
$('#example').DataTable({
serverSide: true,
"columnDefs": [
{ "title": "Sr.", "name": "sr", "width": "5%", "targets": 0 },
{ "title": "ECode", "name": "code", "width": "5%", "targets": 1 },
{ "title": "Employee Name", "name": "name", "width": "25%", "targets": 2 },
{ "title": "Guardian", "name": "guardian", "width": "20%", "targets": 3 },
{ "title": "DOA", "name": "doa", "width": "10%", "targets": 4 },
{ "title": "Department", "name": "department", "width": "20%", "targets": 5 },
{ "title": "Designation", "name": "designation", "width": "20%", "targets": 6 }
],
ajax: {
url: 'employees/listdata/all',
type: 'POST'
}
});
});
</script>
<table id="example" class="display" cellspacing="0" width="100%">
</table>
这里是JSON回复
{
"recordsTotal":842,
"recordsFiltered":842,
"data":[
{"DT_RowId":"28","sr":"1","code":"28","name":"ABHISHEK SHARMA","guardian":"RAMESH CHAND","doa":"10\/12\/2013","department":"Welding Shop","designation":"M. OPERATOR - NUT FORMER"},
{"DT_RowId":"66","sr":"2","code":"66","name":"ACHHAY LAL","guardian":"BAHARAN MAHTO","doa":"26\/06\/2013","department":"Workshop","designation":"STORE KEEPER"},
{"DT_RowId":"454","sr":"3","code":"454","name":"ACHHAY LAL","guardian":"JAI KUMAR","doa":"26\/01\/2015","department":"Cutting Department","designation":"QUALITY CONTROLLER"}
]
}
答案 0 :(得分:0)
我找到了解决方案,它一如既往地非常简单但被忽视了
<script>
$(document).ready(function(){
$('#example').DataTable({
"processing": true,
"serverSide": true,
"columnDefs": [
{ "data": "sr", "title": "Sr.", "name": "sr", "width": "5%", "targets": 0 },
{ "data": "code", "title": "ECode", "name": "code", "width": "5%", "targets": 1 },
{ "data": "name", "title": "Employee Name", "name": "name", "width": "25%", "targets": 2 },
{ "data": "guardian", "title": "Guardian", "name": "guardian", "width": "15%", "targets": 3 },
{ "data": "doa", "title": "DOA", "name": "doa", "width": "10%", "targets": 4 },
{ "data": "department", "title": "Department", "name": "department", "width": "20%", "targets": 5 },
{ "data": "designation", "title": "Designation", "name": "designation", "width": "20%", "targets": 6 }
],
ajax: {
url: 'employees/listdata/all',
type: 'POST'
}
});
});
</script>
<table id="example" class="display" cellspacing="0" width="100%"></table>
我将数据属性添加到每个列,并且它完美地运行。