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]
}],
});
});
In addition to inconsistent and numbers, a missing item inside datatable scripts columns part can cause this too. Correcting that fixed my datatables search bar.
I'm talking about this part;
I struggled with this error till I was pointed that this part had one less "null" than my total thead count.
A common cause for
Cannot read property 'fnSetData' of undefined
is the mismatched number of columns, like in this erroneous code:While the following code with one
<th>
per<td>
(number of columns must match) works:The error also appears when using a well-formed thead with a colspan but without a second row.
For a table with 7 colums, the following does not work and we see "Cannot read property 'mData' of undefined" in the javascript console:
While this works:
You have to remove your
colspan
and the number ofth
andtd
needs to match.In my case, and using ASP.NET GridView, UpdatePanel and with DropDownList (with Chosen plugin where I reset value to zero using a Javascript line), I got this error and tried everything with no hope for days. The problem was that the code of my dropdown in code behind was as follows and when I select a value twice to apply its action to selected grid rows I get that error. I thought for days it's a Javascript issue (again, in my case) and finally the fix was giving zero for the drowpdown value with the update process:
This was my fault:
One more reason why this happens is because of the columns parameter in the DataTable initialization.
The number of columns has to match with headers
I had 7 columns
FYI dataTables requires a well formed table. It must contain
<thead>
and<tbody>
tags, otherwise it throws this error. Also check to make sure all your rows including header row have the same number of columns.The following will throw error (no
<thead>
and<tbody>
tags)The following will also throw an error (unequal number of columns)
For more info read more here