I’ll try to explain the best I can, please let me know if you need additional information.
I’m using a template where datatables are defined like this:
<table id="id_table" class='table table-striped dataTable table-bordered'>
That produces a nice table when data is right there. However, when trying to populate the data via ajax, I get the following error:
DataTables warning (table id = 'id_table'): Requested unknown parameter '1' from the data source for row 0
I confirmed that the php file doesn’t have any issues. If I remove from the table class the ‘dataTable’ part, I get the data with no errors, however the style suffers and the table looks bad. That is, leaving the definition of the table like this:
table id="id_table" class='table table-striped table-bordered'>
(Notice that ‘dataTable’ was removed). With the table as above, all data is there correctly, and the only thing that suffers is the style.
I went to the css (the only one I’m loading) and this is all I could see regarding that class:
.table.dataTable {
border-top: 1px solid #bbb;
border-bottom: 1px solid #bbb;
}
.table.dataTable.dataTable-noheader {
border-top: 0;
}
.table.dataTable.dataTable-nofooter {
border-bottom: 0;
}
The weird thing is that if I change the name of that class, the behavior is the same even if I don’t change the class in the html, is this class something related to datatables? I’m completely lost, I’ve been looking at this for hours now and I can’t see the logic behind all this. Please someone throw a light! 🙂
Are you using some plugin that depends on the dataTable class? It sounds like something is trying to append the data to the table or modify it, and looks for the table by using a css selector on the class name
$(".dataTable"), when you change the class name you’re breaking this selector which is why you don’t see the error anymore.You should try to inspect the data being returned from the ajax call and confirm that it matches whatever your javascript code is expecting.
Edit:
And indeed the datatables FAQ mentions this error:
Apparently the error you’re getting means datatables did not find a value for element at index 1 of the returned JSON array.
Requested unknown parameter '1' from the data source for row 0. Check the JSON data and especially check that you have a value returned for each column in your datatable.