I have a piece of code where I use the datatables plugin.
The table structure looks like this:
<thead>
<tr>
<th>col1</th>
<th>col2</th>
<th>col3</th>
<th>col4</th>
<th>col5</th>
<th>col6</th>
<th>col7</th>
<th>col8</th>
</tr>
</thead>
but notice that in the initialization code I am hiding the last four columns.
In my code, I do the following:
if($data->responseCode < 400)
{
echo HTML Table
}
that works
else
{
echo '<tr><td colspan=4><h1 class="error">'.$data->errorMsg.'</h1></td></tr>';
}
When I do this, I get the following error:
"DataTables warning (table id = 'DataTables_Table_0'): Requested unknown parameter '1' from the data source for row 0"
here is the dataables code:
var oTable = $('.table1').DataTable({
"iDisplayLength": 100,
"aaSortingFixed": [[0,'desc']],
"aaSorting": [ [0,'asc'] ],
"aoColumnDefs": [
{ "bVisible": false, "aTargets": [ 4,5,6,7 ] },
{ "bSearchable": false, "aTargets": [ 1,2,3,4,5,6,7] },
{ "bSearchable": true, "aTargets": [ 0 ] },
]
});
Does anybody know what would be causing that? I thought maybe it was the colspan but when I remove that, the problem still exists. The weird thing is that I use this on another page and it seems to handle an empty result set just fine.
Not sure if this helps but after playing a little I managed to get the following error to show up in firebug:
"TypeError: nTd is undefined"
If you use datatables often, then this is the common error that you will get. The reason is that the data format that you use to create the data table can't match the table columns, for example you have 4 columns while the source data just can provides 3 columns. You can post the data format and the table structure, let me check the further issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With