首页 > 解决方案 > 为什么我的数据表固定标题不起作用/

问题描述

我正在尝试使我的数据表 Thead 成为一个粘性表,但是当我尝试使用固定标题时,它就不起作用了。我已经尝试position: fixed; , top: 0; 并尝试使用 css 修复它,但是当完成此操作时,它在 firefox 中按预期工作,但在 crome edge opera 中无法按预期工作。

    "stateSave": false,
    "orderCellsTop": true,
    "fixedHeader": {
        header: true,
    },
    "columns": [
    {'data':'chk_select_header','orderable': false},

这是我的 ajax 代码。

标签: javascriptjqueryajaxdatatable

解决方案


我曾试图在我的数据表中修复我的thead。但是这个数据表将该广告固定到该页面的顶部,例如https://datatables.net/extensions/fixedheader/examples/options/simple.html但我想坚持该数据表 div 。我发现唯一的方法是使用下面的 CSS 方法

thead tr:first-child Th {
position: sticky;
z-index: 12;
top: 0;
background: white;

}

thead Th {
    position: sticky;
    z-index: 12;
    top: 51px;
    background: white;
}

这是将数据表头粘贴到表头的最简单方法


推荐阅读