Rya*_*ons 6 html css jquery datatables jquery-datatables
我很难让水平滚动与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>
Run Code Online (Sandbox Code Playgroud)
CSS:
.table-striped > tbody > tr:nth-child(odd) > td,
.table-striped > tbody > tr:nth-child(odd) > th {
white-space: nowrap;
}
#portal-drivers {
overflow: auto;
}
Run Code Online (Sandbox Code Playgroud)
JQuery的
$("#portal-drivers").dataTable( {
"scrollX": true
} );
Run Code Online (Sandbox Code Playgroud)
将"scrollX"更改为"sScrollX":'100%'
$("#portal-drivers").dataTable( {
"sScrollX": '100%'
} );
Run Code Online (Sandbox Code Playgroud)
小智 5
尝试将其放入 CSS:
#portal-drivers {
overflow-x: scroll;
max-width: 40%;
display: block;
white-space: nowrap;
}
Run Code Online (Sandbox Code Playgroud)
小智 5
为了使数据表可滚动(标题和正文两者),使用属性sScrollXInner沿着sScrollX如下:
$("#my-demo-datable").dataTable( {
"sScrollX": "100%",
"sScrollXInner": "110%",
} );
Run Code Online (Sandbox Code Playgroud)