Getting DataTables warning: Requested unknown parameter '12' for row 0 sometimes
Getting DataTables warning: Requested unknown parameter '12' for row 0 sometimes
Depending on what the user selects, the table generated will have different number of columns. If I load a 14 column table then try to load a 12 column table, I get "DataTables warning: Requested unknown parameter '12' for row 0." But when I start from the 12 column table, then load the 14 column table, I do not get such a warning. I do not know what I am doing wrong. Everything is inserted fine, and when I go to the next page with pagination, the error doesn't appear. I also do not understand where the '12' is coming from, since I have 12 columns, and I think the warnings do zero-based warnings.
I'm doing server-side processing, and I am adding columns in with a loop, creating DOM elements (I do fnDestroy(), then fnClearTable(), then finally add in my DOM header elements in a loop). I checked the length of the columns, and they always match the length of the inserted rows as expected. Please help me find the part I am missing.
This question has an accepted answers - jump to answer
Answers
First thing to remember is that DataTables column counting is 0 index based - so really the error is about a 13th column. Likely the number of cells in the
tbody
do not match thethead
, or you are usingcolumns
/columnDefs
and it doesn't match the HTML.If you give a link to a page showing the issue I can take a look.
Allan
Hi, I recreated the issue here.
http://jsfiddle.net/o6znk7qw/35/
It appears if I submit the 14 column, then submit the 12 column, but not submitting the 12 column then the 14 column.
Thank you!
Try this: http://jsfiddle.net/o6znk7qw/51/
You had multiple DataTable intialisations which was always going to get really confusing .
I removed the one from
displaytable
since you only want to initialise any one specific table in one location. I've also used$.fn.dataTable.isDataTable()
to check it a table is a DataTable before destroying it and emptying out the old tbody:Allan
Perfect!!! Thank you so much, I really appreciate this great tool and support you all give!