Error initializing DataTable with jquery

1

Hello, I have a DataTable that will be powered by JavaScript Source (data source) when I open the screen, I want it to start "empty" with no data.

For some reason, it already starts automatically when loading jquery.datatable.js, and I need to destroy it and start with my settings. Here comes the problem. Follow the Code:

var table = $('#'+id);  

        table.DataTable().destroy();

        var oTable = table.DataTable( {
                "dom": "<'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r>t<'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>", // datatable layout without  horizobtal scroll
                "scrollY": "300",                               
                "deferRender": true,
                "responsive":true,
                "bAutoWidth": true,                 
                "order": [
                    [0, 'asc']
                    ],
                    "lengthMenu": [
                        [5, 15, 20, -1],
                        [5, 15, 20, "All"] // change per page values here
                        ],
                        "pageLength": 15, // set the initial value  
                data: dataSet,                  
                columns: columns
            } );                

        var tableWrapper = $('#'+id+'_wrapper'); // datatable creates the table wrapper by adding with id {your_table_jd}_wrapper
        tableWrapper.addClass('col-md-12');
        tableWrapper.find('.dataTables_length select').select2(); // initialize select2 dropdown

in line table.DataTable().destroy(); of error

  

Exception caught: Exception caught: Exception caught: (TypeError): Can not read property 'aDataSort' of undefined

I do not know how to solve it, because if I do not give destroy (), I get the message that I can not initialize twice my datatable, and if I try to destroy it to recreate, I get the error mentioned here. Any help is life.

    
asked by anonymous 14.08.2017 / 20:05

0 answers