我正在使用Datatables.net最新的数据表和引导。我想我的问题是:Datatables响应引导使用什么来检测溢出,因为它显然不是父宽度。
这是我的结果:
这是一个很直接的问题。如果我减少我的窗口的宽度1更多的像素,列将最终崩溃。如果我再扩展它,它返回到这个状态。我想防止从父引导面板溢出。我已经删除了引导网格div(row / col-xs-12等)以消除潜在问题,但一旦解决了(或者我更好地理解问题),我打算使用引导网格系统。
这是一个完美复制问题的plunkr(折叠运行视图):
http://plnkr.co/edit/tZxAMOHmdoHNHrzhP5tR?p=preview
- <!DOCTYPE html>
- <html>
- <head>
- <title>Tables - PixelAdmin</title>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>
- <link rel="stylesheet" href="http://cdn.datatables.net/plug-ins/a5734b29083/integration/bootstrap/3/dataTables.bootstrap.css"/>
- <link rel="stylesheet" href="http://cdn.datatables.net/responsive/1.0.2/css/dataTables.responsive.css"/>
- <style>
- body {
- font-size: 140%;
- }
- table.dataTable th,table.dataTable td {
- white-space: nowrap;
- }
- </style>
- </head>
- <body style="padding-top: 40px;">
- <div class="panel panel-primary" style="margin: 51px; padding: 0;">
- <div class="panel-heading">
- <h3 class="panel-title">Panel title</h3>
- </div>
- <div class="panel-body" style="padding: 0;">
- <div style="width: 100%; border: 1px solid red;">
- <table id="example" class="table table-striped table-hover dt-responsive" cellspacing="0" width="100%">
- <thead>
- <tr>
- <th>Name</th>
- <th>Position</th>
- <th>Office</th>
- <th>Extn.</th>
- <th>Start date</th>
- <th>Salary</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- </div>
- <script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
- <script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.3/js/jquery.dataTables.min.js"></script>
- <script type="text/javascript" language="javascript" src="//cdn.datatables.net/responsive/1.0.2/js/dataTables.responsive.js"></script>
- <script type="text/javascript" language="javascript" src="//cdn.datatables.net/plug-ins/a5734b29083/integration/bootstrap/3/dataTables.bootstrap.js"></script>
- <script>
- $(document).ready(function () {
- $('#example')
- .dataTable({
- "responsive": true,"ajax": 'data.json'
- });
- });
- </script>
- </body>
- </html>
解决方法
在表开始前添加具有“表响应”类的Div,并从表标记中删除width =“100%”,
- <div class="panel panel-primary" style="margin: 50px;">
- <div class="panel-heading">
- <h3 class="panel-title">Panel title</h3>
- </div>
- <div class="panel-body">
- <div style="width: 100%; padding-left: -10px; border: 1px solid red;">
- <div class="table-responsive"> // add this div
- <table id="example" class="table table-striped table-hover dt-responsive display nowrap" cellspacing="0"> // remove width from this
- <thead>
- <tr>
- <th>Name</th>
- <th>Position</th>
- <th>Office</th>
- <th>Extn.</th>
- <th>Start date</th>
- <th>Salary</th>
- </tr>
- </thead>
- </table>
- </div>
- </div>
- </div>