【问题标题】:Datatable colVis plugin showing error "headerCells[i] is undefined" when selecting columnDatatable colVis 插件在选择列时显示错误“headerCells[i] is undefined”
【发布时间】:2015-05-14 12:47:43
【问题描述】:

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

我的数据表是

  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 按钮中选择或再次选择列检查时,我在控制台中收到此错误TypeError: headerCells[i] is undefined on line number 4156 jquery.dataTable.js。 在调试时,我发现不知何故列数不会更新,例如最后一个索引如果我在添加(或检查)另一列之前有 5 列。触发的函数只显示计数 5,但它应该返回 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 ) :
                '';
        }

【问题讨论】:

    标签: jquery jquery-plugins datatables jquery-datatables


    【解决方案1】:

    发现问题

    不要使用datables捆绑包

    尝试使用 cdn one 我认为 cdn 解决了同一问题的错误

    &lt;script src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"&gt;&lt;/script&gt;

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2014-08-27
        • 1970-01-01
        • 2013-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-05
        • 1970-01-01
        相关资源
        最近更新 更多