数据表单列搜索与滚动不兼容

Datatables Individual Column Search incompatible with scroll

我正在使用 Datatables to display more than a thousand table rows. I use the individual column search 来搜索特定的列。我用 table 初始化:

var table = $('#example').DataTable( {
        "scrollX": true,
        "scrollY": "400px",
        "paging": false
    });

但是,当我搜索一个列时,第二个左列被第一个(固定的)列溢出。 (请看下图)

我怀疑这是因为每次搜索后重新分配列的宽度:第一列过去也包含较长的用户名,但在搜索后,它的宽度变小了。

我尝试为第一列设置右边距,但没有帮助。

有什么解决办法吗?

请找到演示该问题的 jsfiddle here。您应该搜索 "J".

的职业

Datatables 在 Ajax 呈现后重新计算列宽,所以我认为这是正常行为,但对于您的情况,您可以通过消除

来防止溢出
new $.fn.dataTable.FixedColumns( table );

数据表支持已知此问题已有一段时间了。 (参见 thread) The issue has already been fixed with this changeset,据说是由于:

When scrolling is enabled and column visiblity is toggled a Javascript error would occur due to the column width calculation method cloning the wrong header element.

Datatables' latest nightly release 已经修复了这个问题,但是修复是两行,也可以很容易地添加到当前版本中。

请注意,此问题也影响了 ColVis、单个列搜索和固定列。