Datatables fails to load when table has no rows

Datatables fails to load when table has no rows

JiminyJiminy Posts: 13Questions: 4Answers: 0

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

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    That's because colspan isn't supported within the table - try using language.emptyTable instead. See your example updated here.

    Colin

  • JiminyJiminy Posts: 13Questions: 4Answers: 0

    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

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    No, Colin is correct. The colspan in the tbody is what is causing the DataTable in your original example to choke. In Colin's updated example he uses language.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

  • JiminyJiminy Posts: 13Questions: 4Answers: 0

    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!

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    You'd have to remove it before initialising the DataTable: http://live.datatables.net/gesihiqu/4/edit .

    Allan

  • JiminyJiminy Posts: 13Questions: 4Answers: 0

    Ooh, very clever! Thanks a million :)

This discussion has been closed.