Chained Ajax calls?
Chained Ajax calls?
To get my data, I need to make a chain of Ajax calls to an API, where the 1st call gets a parameter that needs to be sent in the 2nd call, and where the 2nd call gets a parameter that needs to be sent in the 3rd call and so on... When I've gotten all the necessary filter parameters, I can make like the 5th and last call to receive my filtered data. THEN I want to append it to the table. Meanwhile, I want DataTable to show "Loading" as it does for a singel Ajax call.
How do I do this?
This question has an accepted answers - jump to answer
Answers
Don't have DataTables make the Ajax calls at all - do them yourself and use
rows.add()
to add them to the table. While the Ajax calls are happening you could useprocessing()
or similar to show (and then hide when done) a loading indicator.Allan
Thank you! I'm trying that right now but there's no processing function in the API? Do you mean the processing option? If so, nothing happens when I set it to 'true'.
Update: the processing option shows "Processing" while sorting the data but I want it to show while data is being fetched.
Oops - sorry. There is a plug-in for it. I thought I had it in the core, but obviously not yet!
Allan
Use a function for the ajax datatable option (see https://datatables.net/reference/option/ajax ), you then have full control. You can then perform all your ajax calls and only execute the callback (provided as a parameter to the datatable ajax function) when your data is ready.
When table.reload() is called, the ajax function gets executed and 'Processing...' is displayed automatically until the callback is invoked.
Thank you guys! I went with Allan's recommendation to handle the Ajax calls myself. I think I'll use a custom modal for the "Loading"-message. That way I have full control of it's placement and so on.