猿问

如何修复数据表重新初始化

我现在已经修复了好几天了(准确地说是5天),我得到了这个错误。

DataTables警告:表ID =活动表-无法重新初始化DataTable。有关此错误的更多信息,请参见http://datatables.net/tn/3

这是我完整的Jquery代码,此代码在将其分离到一个函数中后就初始化了数据表,以便组织起来:


$(document).ready(function() { 

    initialize_table();

});


function initialize_table(){

    var salesman = $("#salesman-filter").val();

    var supervisor = $("#supervisor-filter").val();

    var startdate = $("#start-date").val();

    var enddate = $("#end-date").val();


    var columns = [

        { "width": "80px", "targets": 0 },

        { "width": "200px", "targets": 1 },

        { "width": "200px", "targets": 2 }, 

        { "width": "200px", "targets": 3 },

        { "width": "200px", "orderable": false, "targets": 4 },

        { "width": "200px", "targets": 5 },

        { "width": "100px", "targets": 6 },

        { "width": "110px", "targets": 7 },

        { "width": "150px", "orderable": false, "targets": 8 },

        { "width": "150px", "orderable": false, "targets": 9 },

        { "width": "150px", "orderable": false, "targets": 10 },

        { "width": "150px", "orderable": false, "targets": 11 },

        { "width": "150px", "orderable": false, "targets": 12 }

    ];


    var table = $('#activities-table').DataTable({

        "serverSide": true,

        "bprocessing": true,

        retrieve: true,

        "ajax": {

            url: "activities-data.php",

            type: "POST",

            data: {salesman:salesman, startdate:startdate, enddate:enddate, supervisor:supervisor},

            error: function(data){

                console.log(data);

            }

        },

        "columnDefs": columns,

        "language": {

            "emptyTable": "No data found",

            "zeroRecords": "No data found",

            "info": "Showing <b>_START_</b> to <b>_END_ of _TOTAL_</b> entries",

            "paginate": {

                "first":      "First",

                "last":       "Last",

                "next":       "Next",

                "previous":   "Previous"

            },

我尝试添加以下内容,但错误仍然不断出现

检索:true
销毁:true

有没有办法解决这个问题?并同时避免?


冉冉说
浏览 189回答 1
1回答

萧十郎

您应该销毁表并重新初始化添加此代码:。$('#activities-table').dataTable().fnDestroy();前:var&nbsp;table&nbsp;=&nbsp;$('#activities-table').DataTable({.....
随时随地看视频慕课网APP
我要回答