Hint for when instantiating DataTable in JQuery and error arises
Hint for when instantiating DataTable in JQuery and error arises
KCS
Posts: 10Questions: 2Answers: 0
I had 4 DataTables in the same CSHTML, initialised using a function passing the relevant Id. One of them was experiencing an issue and JQuery was throwing an exception (although this did not show up till I tried to step in). The remaining 3 DataTables did NOT then initialise. I spent a while looking for non-existent issues in my partial views.
I found that placing each function call in its own try/catch then allowed the non-problematic elements to show as expected.
This discussion has been closed.
Replies
Interesting - because Javascript is single threaded, an exception in the thread will stop anything else that would have subsequently been executed (hence why the other tables weren't initialised).
Its odd that the error message was being swallowed up though - perhaps there is an error handler on the page doing that.
Allan
BTW also found that when using COLUMN options to allow/disallow ordering, that you must also get the number of options exactly right compared to the number of columns, else the DataTable does not initialise, I don't know whether column ordering can be specified by name so you could just specify 2 instead of all.