如何解决为什么我的dataTables功能元素不起作用?
我正在使用数据表对表进行分页。表中的数据来自我的服务器端。 表格中显示了数据,但是表格中显示了消息“表格中没有可用数据” 。
Click here for picture reference
此外,当我尝试数据表的搜索功能和长度更改功能时,数据会突然消失。
这是我的html表:
<table class="table table-striped" id="executives">
<thead>
<th>Employee Number</th>
<th>Name</th>
<th>Department</th>
<th>Position</th>
<th>Action</th>
</thead>
<tbody style="color:black;"id="empTable">
</tbody>
</table>
这是我的数据表:
<script>
$(document).ready(function () {
$('#executives').DataTable({
"paging": "full","bLengthChange": true,"bFilter": true,"lengthMenu": [5,10,25,50,75,100,"All"],"dom": '<"my-wrapper"<"inner-wrapper"<"my-inner0"f><"my-inner1"l><"my-inner1"p>><t><"outer-wrapper"<"my-inner2"i><"my-inner1"p>>">'
});
});
</script>
这是我的JavaScript文件,该文件用于从服务器端获取数据:
$(document).ready(function(){
$.getJSON("URL",function(data){
var empData = [];
$.each(data,function(key,value){
empData.push ("<tr>");
empData.push ("<td id=''"+ key +"''>" + value.empId + "</td>");
empData.push ("<td id=''"+ key +"''>" + value.firstName + "</td>");
empData.push ("<td id=''"+ key +"''>" + value.work.department + "</td>");
empData.push ("<td id=''"+ key +"''>" + value.work.position + "</td>");
empData.push ("<td id=''"+ key +"''>" + value.work.position + "</td>");
empData.push ("</tr>")
});
$('#empTable').append(empData);
console.log(empData);
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。