选择列时数据表 colVis 插件显示错误 "headerCells[i] is undefined"

Datatable colVis plugin showing error "headerCells[i] is undefined" when selecting column

我从早上开始就一直在尝试解决这个错误,但没有效果

我的数据表是

  keywordDataTable = $('#keywordsTable').DataTable( {
    //stateSave: true,
    paging:   false,
    scrollY: "100%",
    scrollX: true,
    scrollCollapse: true,
    dom: 'C<"clear">lfrtip',
    colVis: {
        exclude: [ 0 ],
        showAll: 'All',
        showNone: 'None',
    }
} );
new $.fn.dataTable.FixedColumns( keywordDataTable );

一切正常,但是当我取消选中一列并尝试从 All 按钮或 select 列再次检查 select 时,我在控制台中收到此错误 TypeError: headerCells[i] is undefined on line number 4156 jquery.dataTable.js . 在调试时我发现不知何故列数不会更新和最后一个索引例如如果我在添加(或检查)另一列之前有 5 列。函数触发仅显示计数 5,但它应该 return 6。因此,列宽也未正确设置。

行来自jquery.dataTables.js

headerCells = _fnGetUniqueThs( oSettings, tmpTable.find('thead')[0] );

        for ( i=0 ; i<visibleColumns.length ; i++ ) {
            column = columns[ visibleColumns[i] ];

        /*  (error on this line) */ headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ?
                _fnStringToCss( column.sWidthOrig ) :
                '';
        }

发现错误

不要使用数据表捆绑包

尝试使用 cdn,我认为 cdn 已针对同一问题解决了一个错误

<script src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>

如果您使用JSON绑定网格,请检查您在列定义中的列数是否超过JSON

中的字段数