jquery - 响应式 Bootstrap 数据表未在正确的点折叠列

标签 jquery twitter-bootstrap responsive-design datatables

我正在使用最新的 Datatables.net,带有数据表和 Bootstrap 。我想我的问题是:Datatables Responsive Bootstrap 使用什么来检测溢出,因为它显然不是父宽度。

这是我的结果: enter image description here

这是一个非常简单的问题。如果我将窗口的宽度再减少 1 个像素,该列最终将崩溃。如果我随后扩展它,它会返回到这种状态。我想防止父 Bootstrap 面板溢出。我已经删除了 Bootstrap 网格 div(row/col-xs-12 等)以消除潜在的问题,但是一旦解决了这个问题(或者我更好地理解了问题),我也打算使用 Bootstrap 网格系统。

这是一个完美复制问题的 plunkr(折叠运行 View ): 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>

最佳答案

在表格开始之前添加类为“table-responsive”的 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>

关于jquery - 响应式 Bootstrap 数据表未在正确的点折叠列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26500010/

相关文章:

javascript - 为 JS 对象动态分配属性

javascript - 如何使用 JavaScript 每秒向右移动 10 个像素并向下移动 10 个像素

javascript - 单击容器内部时下拉菜单关闭

jquery - 在 dataTable 上滚动数据应从服务器端加载并附加到现有记录

php - 使用 WordPress 的下拉列表

html - 响应式设计 : CSS Not loading on Iphone 5 Safari

javascript - 外部 Javascript 未调用

javascript - 加载克隆模式( Bootstrap )

javascript - 响应式设计 - 宽表

html - 响应式css两列取消向左浮动