我在使用 dataTables.js 时遇到了横向滚动条无法正常工作的问题。期望的结果是在表格内可以水平滚动,但实际上表格会超出容器 div 的范围。是否有解决方法?
HTML:
<div class="box-body table-responsive">
<table id="portal-drivers" class="table table-bordered table-striped" cellspacing="0" width="100%">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Number</th>
<th>Rating</th>
<th>Transactions</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bugs</td>
<td>Bunny</td>
<td>bugs@tunesquad.com</td>
<td>(310) 530-6789</td>
<td>4.8</td>
<td>309239045293459823945234895</td>
</tr>
</tbody>
</table>
CSS:
.table-striped > tbody > tr:nth-child(odd) > td,
.table-striped > tbody > tr:nth-child(odd) > th {
white-space: nowrap;
}
#portal-drivers {
overflow: auto;
}
jQuery
$("#portal-drivers").dataTable({
"scrollX": true
});
responsive:false
对我很有帮助。我正在使用 ASP Net Zero,它还向表格添加了一个dt-responsive
类,应该将其删除。 - Edmund Gentle