No Data available in table failing to show on no data.
No Data available in table failing to show on no data.
Sometimes my API will return back an error of no user being returned. {"error":"No found users | CODE: XXX-XXX"}
Data Tables is able to show the error message in a alert, however it doesn't update the table to say "No Data available in table" until it's updated in some way (Next page, changing sorting, ETC)
Is there something I can change to allow for it to reload the table correctly to show the "No data available in table" after/before the alert is confirmed.
This question has an accepted answers - jump to answer
Answers
Hi @Alipoodle ,
That depends on how your API is interacting. We're happy to take a look. As per the forum rules, if you could link to a running test case showing the issue we can offer some help. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
https://jsfiddle.net/aed7jrq8/2/
This is roughly the same as what I'm using, with the exception of the files being provided are static in this case.
Loading the page will pre-load an example and upon clicking the button it will provide with the JSON I had posted above, showing the error with an alert and leave the table in the same state as it was.
Upon changing the number of shown values or the column it's sorting in, it will update and the "No Data available...."
Hi @Alipoodle ,
Thanks for that demo - I think the problem is just because the data isn't in the expected format. The API should be returning just an empty JSON object - {"data":[]} rather than an error mesage.
If you aren't able to change the API, you could preparse the server responses in
ajax.dataSrc
, detect the error and change it to the expect format there.Cheers,
Colin
Many Thanks!