1
Hello, I have a Datatable that will be fed with Javascript Source (data source) when opening the screen, I want it to be started "empty", without 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
on the line table.DataTable().destroy();
of the error
Exception Caught: Exception Caught: Exception Caught: (Typeerror) : Cannot read Property 'aDataSort' of Undefined
I don’t know how to solve it, because if I don’t give Destroy(), I get the message that I can’t initialize my datatable twice, and if I try to destroy it to recreate it, I get the error mentioned here. Any help is good.
We will need the HTML that generates the table.
– user86792
My table html is simple
<table id="myTable" class="datatable"></table>
since columns and dice are not made by the DOM.– Jeterson Miranda Gomes