为什么我的数据表固定标题不起作用/

5 javascript ajax datatable jquery

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

    "stateSave": false,
    "orderCellsTop": true,
    "fixedHeader": {
        header: true,
    },
    "columns": [
    {'data':'chk_select_header','orderable': false},
Run Code Online (Sandbox Code Playgroud)

这是我的 ajax 代码。

小智 6

我曾尝试在数据表中修复我的标题。但是这个数据表将该标题固定到页面顶部,如下所示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;
}
Run Code Online (Sandbox Code Playgroud)

或者

thead th {
    position: sticky;
    z-index: 12;
    top: 51px;
    background: white;
}
Run Code Online (Sandbox Code Playgroud)

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