【发布时间】:2021-01-23 20:28:12
【问题描述】:
表已加载数据,但在几毫秒后数据表清除了加载的数据,并且一行出现消息“未找到匹配记录”
HTML Code
<table id="table">
<thead>
<tr>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
<th><span class="table_header">Heading</span></th>
</tr>
</thead>
<tbody>
<?php get_data_from_db(); ?>
</tbody>
get_data_from_db(); 是一个函数,它以下面的形式返回行。
$record = <<<DELIMETER
<tr> // Repeated with data </tr>
DELIMETER;
echo $record;
这里是 Javascript 代码
$('#table').DataTable();
链接数据表文件
<!-- Datatable css -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css">
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.6.2/css/buttons.bootstrap4.min.css">
<!-- Datatable JS-->
<script src="http://cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="http://cdn.datatables.net/1.10.21/js/dataTables.bootstrap4.min.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/dataTables.buttons.min.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/buttons.bootstrap4.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
<script src="http://cdn.datatables.net/buttons/1.6.2/js/buttons.html5.min.js"></script>
【问题讨论】:
-
我也面临同样的问题
-
无法从我看到的内容中分辨出来。但请确保 html 已正确生成,其次查看
$.DataTable()是否尝试在 dom 就绪状态之前启动。它需要渲染 html 才能正常工作。 -
我验证了生成的 html 三个以上但仍然相同,并且 javascript 代码在
$(document).ready(function(){});
标签: html jquery bootstrap-4 datatable