I have a issue with Datatables
. I also went through this link which didnt yield me any result.I have inlcuded all the prerequisites where am parsing data directly into the DOM. Kindly help me to fix this issue.
Script
$(document).ready(function() {
$('.viewCentricPage .teamCentric').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": false,
"bFilter": true,
"bSort": true,
"aaSorting": [
[1, "asc"]
],
"aoColumnDefs": [{
"bSortable": false,
"aTargets": [0]
}, {
"bSortable": true,
"aTargets": [1]
}, {
"bSortable": false,
"aTargets": [2]
}],
});
});
I had this same problem using DOM data in a Rails view created via the scaffold generator. By default the view omits
<th>
elements for the last three columns (which contain links to show, hide, and destroy records). I found that if I added in titles for those columns in a<th>
element within the<thead>
that it fixed the problem.I can't say if this is the same problem you're having since I can't see your html. If it is not the same problem, you can use the chrome debugger to figure out which column it is erroring out on by clicking on the error in the console (which will take you to the code it is failing on), then adding a conditional breakpoint (at
col==undefined
). When it stops you can check the variablei
to see which column it is currently on which can help you figure out what is different about that column from the others. Hope that helps!This can also occur if you have table arguments for things like
'aoColumns':[..]
which don't match the correct number of columns. Problems like this can commonly occur when copy pasting code from other pages to quick start your datatables integration.Example:
This won't work:
But this will work:
Slightly different problem for me from the answers given above. For me, the HTML markup was fine, but one of my columns in the javascript was missing and didn't match the html.
i.e.
My Script:-
in my case this error occured if i use table without header
You need to wrap your your rows in
<thead>
for the column headers and<tbody>
for the rows. Also ensure that you have matching no. of column headers<th>
as you do for thetd
I found some "solution".
This code doesn't work:
But this is ok:
I think, that the problem is, that the last TH can't have attribute colspan.