Why does the error function option not work as described?
Why does the error function option not work as described?
I have a function called displayError() which displays errors in a nice modal.
If I set DataTables to use this function, like so . . .
$.fn.dataTable.ext.errMode = function ( message ) {
displayError( 'An error was encountered trying to create the Data Table: ' + message );
};
it still throws a message instead of calling my function.
I have looked at the source code and there is nothing there that I can see that supports the above functionality.
Any ideas?
This question has an accepted answers - jump to answer
Answers
Are you using the nightly version of DataTables? I think it is only available there until I release 1.10.5.
Allan
Works perfectly on the nightly build.
Thanks Alan
After testing it further, I have one suggestion:
I you pass 3 parameters to the error function:
(settings, help_page_number, message)
Unfortunately you mangle the message with your own wording, e.g.
"DataTables warning: table id=MattersBrowseTable - My error"
which makes it hard for me to extract the message I actually raised, in this case "My error".
I think it is unwise to presume that this is the wording I would want to show my users.
Can you add a 4th parameter, maybe, which has just the error text, e.g. "My error" or preferably just return the unadulterated error message as the 3rd parameter.
Your comments?
I also notice that it then fails to create a "No records" table and so I get an error in the console:
Uncaught TypeError: Cannot read property 'length' of undefined
I think it should fail gracefully.
I would suggest never showing these messages to your users :-). They are errors that are there for the use of developers only. If an error is shown then there is a problem that should be fixed.
Please link to a test case showing the issue so I can debug it.
Allan
Try this:
Test.json
{"error": "My custom error"}
I see - thanks. As a workaround at the moment you could either:
data
array to the JSON return.I'll have a think about the best way to handle this in DataTables core.
Allan