【发布时间】:2020-08-12 21:36:11
【问题描述】:
DataTables 遇到了一个奇怪的问题。基本上,我所拥有的是一个不是全宽的容器,并且在该 div 内我有 table 元素:
<div style="width: 50%;">
<table id="example3" class="display nowrap table table-bordered table-striped table-sm" style="width:100%">
<thead>
<tr>
<th>ID</th>
<th>First name</th>
<th>Last name</th>
<th>ZIP / Post code</th>
<th>Country</th>
</tr>
</thead>
</table>
</div>
我正在初始化表格:
$(document).ready(function() {
var data = [];
for (var i = 0; i < 10000; i++) {
data.push([i, i, i, i, i]);
}
$('#example3').DataTable({
data: data,
scrollX: true
});
});
现在,我希望这会起作用,但我最终得到的是:
注意标题列如何与数据不匹配。
如果我删除“table-sm”类或者容器/表格的宽度为 100%,这将非常有效。我尝试了其他方法,例如手动更新列 (table.columns.adjust()),但似乎没有任何效果。
有人对如何解决这个问题有任何见解或想法吗?
jsFiddle 显示问题:https://jsfiddle.net/vnbm8eh0/
【问题讨论】:
标签: javascript jquery datatables