jquery - 水平滚动 dataTables.js

标签 jquery html css 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>

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
} );

最佳答案

将“scrollX”更改为“sScrollX”:'100%'

$("#portal-drivers").dataTable( {
    "sScrollX": '100%'
} );

关于jquery - 水平滚动 dataTables.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24717184/

相关文章:

javascript - jQuery 视频叠加按钮

javascript - jQuery 将不在我的 html 字符串中的行添加到表中

html - 使用 Bootstrap 从无序列表中删除元素符号

javascript - 模拟水平行内 block 元素,但元素高度可以绕过它们的行内高度

javascript - CSS 仅影响嵌套列表中的父列表

javascript - 使用 jquery 序列化无序列表

php - 点击链接后 JQuery 提交表单

javascript - 垂直菜单导航上的 jquery Accordion 鼠标悬停和鼠标悬停

javascript - 根据窗口大小动态调整div

html - 如何编写覆盖主题 CSS 的插件 CSS