Equivalent of xhr event for *after* the ajax data has loaded

Equivalent of xhr event for *after* the ajax data has loaded

creidiekicreidieki Posts: 7Questions: 3Answers: 0

The documentation of the xhr event https://datatables.net/reference/event/xhr says that it's called "before DataTables has processed the new data from the server, so the returned data will not have been drawn on page when this event fires." What's the equivalent for triggering something afterwards?

(Documentation question, so no test case, just link to documentation.)

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769
    edited March 2021 Answer ✓

    I would say the draw event. But the draw event will happen at other times. I don't think there is a specific event that follows the xhr event. See this example for some of the events to see their order when the Datatable is initialized.
    http://live.datatables.net/qosupeti/5/edit

    What are you looking to do after the xhr event?

    Kevin

  • creidiekicreidieki Posts: 7Questions: 3Answers: 0

    Heh, yeah, I had settled on the draw event. I started typing a detailed explanation of my problem, and in the process figured out how to fix it in a cleaner way. Thanks again for your help!

    (In case you're interested, I had a button in each row of the table, and I was using the table init event to attach handlers to them. I needed to figure out how to reattach handlers after a table.ajax.reload(), using the function argument to that.)

  • kthorngrenkthorngren Posts: 20,300Questions: 26Answers: 4,769
    edited March 2021

    Another option is to use delegated events as shown in this example. Then you won't need to worry about adding event handlers. Here is a running example with buttons:
    http://live.datatables.net/xijecupo/1/edit

    Kevin

This discussion has been closed.