Chained Ajax calls?

Chained Ajax calls?

Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

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

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    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 use processing() or similar to show (and then hide when done) a loading indicator.

    Allan

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    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'.

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0
    edited May 2017

    Update: the processing option shows "Processing" while sorting the data but I want it to show while data is being fetched.

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Oops - sorry. There is a plug-in for it. I thought I had it in the core, but obviously not yet!

    Allan

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    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.

  • Rawland_HustleRawland_Hustle Posts: 94Questions: 16Answers: 0

    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.

This discussion has been closed.