DataTables警告:无法重新初始化DataTable

时间:2018-05-23 10:59:10

标签: javascript datatable

我的JS代码:     

function filtre() {
    var status = document.getElementById("filtre").value;
    $.get("users/liste/" + status, function (data) {
        $("#example2_wrapper").DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": "../admin/users/liste/" + status,
            "aoColumns": [
                {mData: "id"},
                {mData: "name"},
                {mData: "user_level"},
                {mData: "location"},
                {mData: "gender"},
                {mData: "status"},
                {mData: "islem"}
            ]
        });
    });
}

我无法用我的数据填充数据包。它的类型是JSON,它是数据表的需要。错误是

  

DataTables警告:table id = example2_wrapper - 无法重新初始化DataTable

1 个答案:

答案 0 :(得分:0)

看起来你在第一次初始化后正在初始化表

试试这段代码

function filtre() {
    var status=document.getElementById("filtre").value;
    $.get('users/liste/' + status, function (data) {
        $('#example2_wrapper').DataTable({

            "destroy": true,                

            "processing": true,
            "serverSide": true,
            "ajax": "../admin/users/liste/"+status,
            "aoColumns": [
                {mData: "id"},
                {mData: "name"},
                {mData: "user_level"},
                {mData: "location"},
                {mData: "gender"},
                {mData: "status"},
                {mData: "islem"}
            ]
        });
    } );
}

所以破坏现有的表然后重新初始化