Why am I getting a TypeError within my datatable?
Why am I getting a TypeError within my datatable?
BradleyO07
Posts: 13Questions: 10Answers: 0
I am currently building a datatable and I keep getting this error code within my table:
Uncaught TypeError: Cannot read properties of undefined (reading 'sWidth')
Below is my code:
var mainDT;
/**
* Generates the Tables
*/
function getTable() {
mainDT = $('#siloTable').DataTable({
display: 'envelope',
ajax: {
'type': 'POST',
'url': '../ajax/silo/SiloTable.ajax.php',
'data': {
'getTable': 1,
}
},
table: ('#siloTable'),
scrollX: true,
order:[[ 0, "desc" ]],
iDisplayLength: 25,
fixedColumns: true,
dom:
"<'row'<'col-8 col-md-4 col-lg-3'l><'col-md-6 col-lg-8 d-none d-md-block text-center'><'col-2 col-md-2 col-lg-1 button-right'B>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
columns:[
{ data: "sample_datetime" },
{ data: "recycle" },
{ data: "preset" },
{ data: "weight" },
{ data: "preact" },
{ data: "dribble" },
{ data: "concet" },
],
buttons: ['csv'],
});
}
$(document).ready(function(){
getTable();
});
Can anyone help me on why I am getting this error?
This question has an accepted answers - jump to answer
Answers
Its hard to say without seeing a page with the issue. It sounds like you might have a missing column where Datatables is trying to apply the width. Start by making sure your
thead
has 7 columns to match thecolumns.data
. If you still need help please provide a link to your page or a test case replicating the issue so we can help debug.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin