【问题标题】:IE errors when destroying DataTable销毁 DataTable 时出现 IE 错误
【发布时间】:2017-02-06 17:01:10
【问题描述】:

我的项目在 Internet Explorer 10 和 DataTable.destroy() 之间遇到了兼容性问题。我有很多 DataTable,当我更改或添加数据时,我使用 Ajax 和 $("#" + this.id).DataTable.destroy() 来重建表。

以下是用于初始化 DataTables 的代码:

        $('.tableReleves').each(function( index ) {
        if(this.childElementCount>1) {
            $("#" + this.id).DataTable({
                "paging": true,
                "info": false,
                "searching": false,
                "retrieve": true,
                "language": {
                    "paginate": {
                        "previous": "«",
                        "next": "»",
                    }
                },
                "columnDefs": [
                    {"type": "currency", "targets": this.id.contains('apres') ? [-2, -1] : -1}
                ]
            });
        }
    });
    toDestroy = true;    

更新或添加新数据后,我用它来更新我的数据表

if(toDestroy) {
    $('.tableReleves').each(function( index ) {
        if(this.childElementCount>1) {    
            $("#" + this.id).DataTable.destroy()
        }
})

}

(toDestroy变量用于避免在页面加载过程中调用该部分)

这在 chrome 或 Firefox 上运行良好,但在 IE 上显示错误。

无法获取属性“样式”的值:对象为空或 未定义

我尝试了一些方法,例如 draw()、clear(),但在三个 Web 浏览器上都没有任何效果。

谢谢。

【问题讨论】:

    标签: jquery ajax internet-explorer datatables


    【解决方案1】:

    虽然这是一个非常古老的帖子,但由于我遇到了同样的问题,所以我在这里标记了我所做的解决方案。我的代码在除 IE 之外的其他浏览器中也能正常工作。如果class datatable 没有与table 标签相关联,IE 会出现破坏数据表函数的问题。

    在销毁之前检查表有classdatatable。按照此处所述更改您的代码。

    if(toDestroy) {
        $('.tableReleves').each(function( index ) {
            if(this.childElementCount > 1) {   
              if ($("#" + this.id).hasClass('dataTable')) {
                $("#" + this.id).DataTable.destroy();
             }
          }
    })
    

    【讨论】:

      猜你喜欢
      • 2012-08-21
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-24
      • 1970-01-01
      • 2022-12-19
      • 1970-01-01
      相关资源
      最近更新 更多