【发布时间】:2017-02-22 11:07:40
【问题描述】:
我在代码中使用了 Datatable,但搜索、排序和分页不起作用 我调用了静态函数。数据在表中成功显示,但是当我搜索任何显示“无匹配记录”的数据时搜索不起作用,因为我输入的文本存在于表中
检查 GIF 图片
https://i.stack.imgur.com/YDK1S.gif
这就是我的尝试
<table id="example" class="display nowrap cell-border" style="width:100%;" cellspacing="0">
</table>
<script type="text/javascript">
success: function (result) {
$("#example").empty()
if (re.length > 0) {
$("#example").append
("<thead><tr><th>Service Type</th><th>Service frequency</th><th>Last performed</th><th>Next Service</th><th>Create reminder</th></tr></thead>");
for (var i = 0; i < re.length; i++) {
if (re[i] !== null) {
$("#example").append("<tbody><tr><td>" +
re[i][0] + "</td><td>" +
re[i][1] + "</td><td>" +
re[i][2] + "</td><td>" +
re[i][3] + "</td><td>" +
re[i][4] + "</td></tr></tbody>");
sdate = re[i][2];
}
}
}
var myTable = $('#example').DataTable();
},
</script>
链接
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdn.rawgit.com/bpampuch/pdfmake/0.1.18/build/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.html5.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href=" https://cdn.datatables.net/buttons/1.2.2/css/buttons.bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.2.2/js/buttons.bootstrap.min.js"></script>
<link href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" rel="stylesheet" />
检查 gif 图片
【问题讨论】:
-
使用 myTable .draw();
-
在哪里? @VenkataKrishnaReddy
-
在 var myTable = $('#example').DataTable(); 之后
-
我试过了,但是不行
-
查看您的代码,您似乎在每一行行周围都有一个
<tbody>。这是无效标记,可能是您的问题的原因
标签: jquery css search datatables