Datatables fails to load when table has no rows
Datatables fails to load when table has no rows

Link to test case: http://live.datatables.net/gesihiqu/1/edit
Debugger code (debug.datatables.net):
Error messages shown: the console shows "Uncaught TypeError: nTd is undefined"
Description of problem: The test case demonstrates the problem.The app server framework that we use, when there are no rows to be shown, generates a single TR with a single TD of whatever colspan is needed. This seems to be breaking the loading of Datatables, with the knock-on effect of breaking e.g. columns that we hide using Datatables.
As we don't really have the possibility of changing the underlying generated HTML, is there any solution to handling this from the Datatables side?
thanks! This is my first question, so hopefully I have done it correctly here!
This question has an accepted answers - jump to answer
Answers
That's because
colspan
isn't supported within the table - try usinglanguage.emptyTable
instead. See your example updated here.Colin
Hi Colin!
thanks very much for the quick response - I really appreciate it.
Just to satisfy my curiosity, I have a follow on question: it seems from your solution that the problem isn't the colspan itself, but rather the missing language.emptyTable - am I understanding that correctly, or is there some point that I'm missing?
many thanks
No, Colin is correct. The
colspan
in thetbody
is what is causing the DataTable in your original example to choke. In Colin's updated example he useslanguage.emptyTable
to have DataTables draw that message into the table if there is no data available in the table (instead of having it in the static HTML).Allan
Hi Allan!
thanks very explaining - I've just realised that in Colin's example he actually commented out the table row entirely, thus removing the colspan, I had missed that detail - so that explains it.
Unfortunately I don't think that the language.emptyTable is going to work in my case, as I have very little control over the underlying HTML, and don't think I can remove the colspan. Is there any other approach that could work?
thanks!
You'd have to remove it before initialising the DataTable: http://live.datatables.net/gesihiqu/4/edit .
Allan
Ooh, very clever! Thanks a million