细节 header 在 jQuery 数据 table 主细节设置中的高度为零

Detail header has zero height in jQuery data table master detail setting

我正在尝试实现一个 master-detail 数据 table,除了 header 详细数据 table 没有显示外,大部分工作正常。当我检查 header 时,我发现它的高度为零。

我在谷歌上搜索了一个解决方案,似乎可以解释问题的一件事是,当 table 被隐藏然后被初始化时,它以 header 结束,页脚的高度为零。

我尝试了一些方法来修复它,但都无济于事。我会很感激一些建议。

这是我所拥有并尝试过的:

// Master data tabl
<table id="AITable" class="table table-striped table-bordered table-hover display compact">
    <thead>
        <tr>
            <th></th>
            <th>Col 1</th>
            <th>Col 2</th>
        </tr>
    </thead>
    <tbody>
    </tbody>
    <tfoot>
    </tfoot>
</table>

<script type="text/javascript">
    var iTableCounter = 1;
    var oInnerTable = new Object;

    var tblAI = $("#AITable").DataTable({
        jQueryUI: true,
        data: [],
        dom: 'frtip',
        scrollY: 450,
        scrollCollapse: true,
        autoWidth: true,
        paging: false,
        sortCellsTop: true
        },
        "columns": [
            {
                "className": 'details-control',
                "orderable": false,
                "data": null,
                "defaultContent": ''
            },
            {
                "data": "COL1"
            },
            {
                "data": "COL2"
            }
    });

    function addDataTableListener() {
        // Add event listener for opening and closing details
        $('#AITable tbody').on('click', 'td.details-control', function () {
            var tr = $(this).closest('tr');
            var row = tblAI.row(tr);
            var col1 = row.data().COL1;

            if (row.child.isShown()) {
                // This row is already open - close it
                row.child.hide();
                tr.removeClass('shown');
            }
            else {
                // Add the html table shell of the datatable.
                row.child(formatEDLTableDetailRow(iTableCounter)).show();

                //show the datatable row.
                tr.addClass('shown');

                // try datatable stuff
                oInnerTable = buildSubDataTable(row.data(), iTableCounter);
                populateSubTable(oInnerTable, col1);
                iTableCounter = iTableCounter + 1;
            }
        });
    }

    $(document).ready(function () {
        // This populates the top data table
        populateAITable(-1);
        addDataTableListener();
        ...
    });

    function buildSubDataTable(parentObjData, tableCounter) {

        //if ($.isEmptyObject(oInnerTable)) {
            oInnerTable = $("table#itemsDataTable_" + tableCounter).DataTable({
                jQueryUI: true,
                data: [],
                dom: 'tip',
                info: false,
                showEntries: false,
                autoWidth: false,
                paging: false
                },
                "columns": [
                    {
                        "orderable": false,
                        "data": null,
                        "defaultContent": ''
                    }, {
                        "data": "COL3",
                        "title": "Col 3"   // Tried adding "title", didn't work
                        }
                    },
                    {
                        "data": "COL4",
                        "title": "Col 4"
                    }
                ],
                "columnDefs": [
                    ...
                ],
                "fnInitComplete": function () {  // Tried this, didn't work
                    this.fnAdjustColumnSizing()
                }
            })
        //}
        return oInnerTable;
    }

    function populateSubTable(oInnerTable, someID) {
        $.ajax({
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            url: "../WebService/AIR.asmx/GetSomething",
            cache: false,
            data: JSON.stringify({ SomeID: someID }),
        }).done(function (result) {
            oInnerTable.clear().draw();
            if (!result || result.d === "") {
            }
            else {
                jResult = JSON.parse(result.d);
                oInnerTable.rows.add(jResult).draw();
                oInnerTable.draw(false);
            }
        }).fail(function (jqXHR, textStatus, errorThrown) {
        });
    }

    function formatTableDetailRow(table_id) {
        // Tried adding class "header" with "height" and "line-height" set to 2rem; didn't help
        var tblMarkup = 
            '<div style="font-size: 1rem">' +
                '<table id="itemsDataTable_' + table_id + '" class="table table-striped table-bordered table-hover responsive display compact pull-left">' +
            '        <thead class="header">' +
            '            <tr class="header">' +
            '                <th></th>' +
            '                <th>Col 3</th>' +
            '                <th>Col 4</th>' +
            '            </tr>' +
            '        </thead>' +
            '        <tbody></tbody>' +
            '    </table>' +
            '</div>';
        return tblMarkup;
    }

代码没有问题,按预期工作。 header 行未显示的原因低于 CSS:

table#AITable thead {
    visibility: collapse;  <-- commented this out and header showed.
}