columns and columnDefs not working together
columns and columnDefs not working together
[Datatables 1.10.18]
Given the following snippet does not work. I get an error that says : Cannot set property '_DT_CellIndex' of undefined TypeError: Cannot set property '_DT_CellIndex' of undefined
let resultTable = $('table#results').DataTable( {
"dom": 'Bfrtip',
"columns": [
{ "name": "colPlant" },
{ "name": "colPartNum" },
{ "name": "colStatus" },
{ "name": "colCustomers" },
{ "name": "colComments" },
{ "name": "colAction" }
],
"columnDefs": [{ "bSortable": false,
"targets": [ "colCustomers", "colComments"]}
]
});
I'm trying to set the names of the columns so I can use those names in the targets to make updating in the future easier.
Meanwhile, this works:
let resultTable = $('table#results').DataTable( {
"dom": 'Bfrtip',
"columnDefs": [{ "bSortable": false, "targets": [ 3, 4]} ]
});
Can anyone advise what I'm doing wrong? Is the syntax wrong? Can you use columns and columnDefs in the datatable instantiation like that or are you supposed to use them separately?
This question has an accepted answers - jump to answer
Answers
I figured it out, I had one too many column names. I removed the bogus column and it works now.
According to the
columnDefs.targets
docs you can supply one of the following:Since you are providing a string its looking for a class name. This, I suspect, is why you are getting the
_DT_CellIndex' of undefined
error. You can assign a class with thecolumns.className
option.The
columns.name
is used with Datatables API's to select the column. It is not intended for use with options.Kevin