Using our Rest API to pass data to Data Tables
Using our Rest API to pass data to Data Tables
murpg
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
This discussion has been closed.
Answers
How do we do this?
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 todata.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 examplejson.draw = json.data.DATA.draw;
. Unfortunately, you would also need to overwrite your top leveldata
object with the data array.Allan
Thanks for writing back Allan. How about duplicating the json object and then manipulating the copy?
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