水平滚动dataTables.js

时间:2014-07-12 20:48:51

标签: 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
} );

4 个答案:

答案 0 :(得分:8)

更改&#34; scrollX&#34;到&#34; sScrollX&#34;:&#39; 100%&#39;

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

答案 1 :(得分:5)

为了使数据表可滚动(标题和正文),请使用属性sScrollXInnersScrollX,如下所示:

$("#my-demo-datable").dataTable( {
    "sScrollX": "100%",
    "sScrollXInner": "110%",
} );

答案 2 :(得分:4)

尝试将其放入CSS:

#portal-drivers {
    overflow-x: scroll;
    max-width: 40%;
    display: block;
    white-space: nowrap;
}

答案 3 :(得分:-1)

为了使数据表可滚动,您可以试试这个

$(document).ready(function() {
    $('#example').DataTable( {
        *"scrollY": 200,
        "scrollX": true
    } );
} )
相关问题