serverSide data from await function() ?

serverSide data from await function() ?

MarcusRMarcusR Posts: 3Questions: 1Answers: 0

I want to source table data from an asynchronous javascript function that calls a remote REST Api. The Api accepts limit and offset request parameters but they are different from DataTable's draw/start/length (etc) request parameters. The Api returns data that I will need to reformat to match DataTable's draw/recordsTotal/recordsFiltered response parameters. So I will need to catch and modify outgoing and incoming Request and Response data.
So my question is this: Can I substitute DataTable's ajax method with something like
data: await api.getData(params) ?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,110 Site admin
    Answer ✓

    Yes - assuming you are building the DataTable inside an async function, then that will work just fine since it will wait for the response from api.getData() which is presumably JSON.

    Allan

  • MarcusRMarcusR Posts: 3Questions: 1Answers: 0

    Thank you allan! It took me a little while to figure it out, but if you put your await function inside DataTable's ajax: property then trigger callback with the final data - it works!

This discussion has been closed.