使用 jquery 数据表我无法在不破坏 FixedHead 的情况下创建单元格 colspan=3

Using jquery datatables I can't make a cell colspan=3 without breaking FixedHead

我有一个 fixedhead 数据表,向下滚动时前 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

来自 DataTables complex header 文档:

Note that each column must have at least one unique cell (i.e. a cell without colspan) so DataTables can use that cell to detect the column and use it to apply ordering.

在您的示例中,您尝试应用 colspan 的 header column 不包含 "unique cell".

但是,您可以解决这个问题,方法是添加一个没有 colspan 的标题行,然后将其 css 设置为 display:none;:

fiddle

Header 示例:

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