Using our Rest API to pass data to Data Tables

Using our Rest API to pass data to Data Tables

murpgmurpg Posts: 3Questions: 1Answers: 0

We have a rest api that we want to use to pass the data to DataTables. In the json coming back from our API the data is at data.DATA.data

Answers

  • murpgmurpg Posts: 3Questions: 1Answers: 0

    How do we do this?

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    If you aren't using server-side processing then its simply a matter of using the ajax.dataSrc option - in this case it would be set to data.DATA.data.

    However, it looks like you are using server-side processing. For that DataTables requires that the server-side parameters be available at the top level of the JSON data - I'm afraid there is no way around that fact at the moment. You can use the xhr event to modify the JSON object returned from the server before DataTables uses it (for example json.draw = json.data.DATA.draw;. Unfortunately, you would also need to overwrite your top level data object with the data array.

    Allan

  • murpgmurpg Posts: 3Questions: 1Answers: 0

    Thanks for writing back Allan. How about duplicating the json object and then manipulating the copy?

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    DataTables wouldn't read the duplicate I'm afraid - it currently only uses the original object. You could duplicate it and use the duplicate else where in your application if you need it, and then manipulate the original.

    Allan

This discussion has been closed.