【问题标题】:Using jquery datatables I can't make a cell colspan=3 without breaking FixedHead使用 jquery 数据表我不能在不破坏 FixedHead 的情况下制作单元格 colspan=3
【发布时间】:2015-05-04 15:27:12
【问题描述】:

我有一个固定头数据表,向下滚动时前 4 行固定在顶部,问题是当我尝试使第二行 colspan=3 显示“让我 colspan=3”时,数据表丢失它能够固定在顶部。我不知道为什么这会影响数据表。谢谢您的帮助。 代码:http://jsfiddle.net/xF8hZ/139/

<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
    <tr>
        <th colspan=3></th>
        <th colspan=3>234</th>
    </tr>
    <tr>
        <th>Make me </th>
        <th>colspan</th>
        <th>=3</th>
        <th>
            <p class="rotatehead">Hazmat</p>
        </th>
        <th>
            <p class="rotatehead">Out of Area</p>
        </th>
        <th>
            <p class="rotatehead">Lite</p>
        </th>
    </tr>

更新:我刚刚在添加 colspan=3 后看到了我的控制台,我收到了这个错误:

Uncaught TypeError: Cannot read property 'style' of undefinedjquery.dataTables.js:4138 _fnCalculateColumnWidthsjquery.dataTables.js:3265 _fnInitialisejquery.dataTables.js:6521 (anonymous function)jquery-1.8.3.js:611 jQuery.extend.eachjquery-1.8.3.js:241 jQuery.fn.jQuery.eachjquery.dataTables.js:6047 DataTablejquery.dataTables.js:14691 $.fn.DataTablepriceadjustment.html:30 (anonymous function)jquery-1.8.3.js:974 jQuery.Callbacks.firejquery-1.8.3.js:1084 jQuery.Callbacks.self.fireWithjquery-1.8.3.js:406 jQuery.extend.readyjquery-1.8.3.js:83 DOMContentLoaded

【问题讨论】:

    标签: javascript jquery css datatable jquery-datatables


    【解决方案1】:

    来自DataTables complex header 文档:

    请注意,每一列必须至少有一个唯一的单元格(即没有 colspan 的单元格),以便 DataTables 可以使用该单元格来检测列并使用它来应用排序。

    在您的示例中,您尝试将 colspan 应用到的标题 column 不包含“唯一单元格”。

    但是,您可以通过添加一个不带colspan 的头行然后将其css 设置为display:none; 来解决这个问题:

    fiddle

    标题示例:

     <thead>
            <tr>
                <th colspan=3></th>
                <th colspan=3>234</th>
            </tr>
            <!-- ADDED: Placeholder row for sorting -->
            <tr class="place">
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
                <th></th>
            </tr>
            <!-- END Placeholder row for sorting -->
            <tr>
                <th colspan="3">Make me colspan = 3</th>
                <th>
                    <p class="rotatehead">Hazmat</p>
                </th>
                <th>
                    <p class="rotatehead">Out of Area</p>
                </th>
                <th>
                    <p class="rotatehead">Lite</p>
                </th>
            </tr>
            <tr>
                <th colspan=3>RACK</th>
                <th>
                    <div contenteditable>234</div>
                </th>
                <th>
                    <div contenteditable>234</div>
                </th>
                <th>
                    <div contenteditable>234</div>
                </th>
            </tr>
            <tr>
                <th colspan=3>TOTAL</th>
                <th>
                    <div contenteditable>234</div>
                </th>
                <th>
                    <div contenteditable>234</div>
                </th>
                <th>
                    <div contenteditable>345</div>
                </th>
            </tr>
        </thead>
    

    添加了 CSS:

    .place{
        display: none;
    }
    

    【讨论】:

    • 太棒了!答案和解决方法。谢谢,我很感激!
    • 谢谢!很高兴能提供帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    • 2021-02-25
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    相关资源
    最近更新 更多