JSON object as a datasource without AJAX
JSON object as a datasource without AJAX
frSurfer
Posts: 7Questions: 3Answers: 0
I have a JSON object like this:
{"status":"success","data":[{"club_code":"3P","club_id":"1020001","club_name":"STAGE ROBERT DAL FARRA"},{"club_code":"6D","club_id":"1020002","club_name":"BRIDGE VOYAGES SUD OUEST"},{"club_code":"1-","club_id":"1020003","club_name":"STAGE FRANCK BUSSELIER"}]}
What is the correct syntax to display the "data" list in a DataTable?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
In your case you can specify your data source as "data".
https://www.datatables.net/examples/ajax/custom_data_property.html
if you are using api instance - you can use the following code (if you already have a json)
***** here "data" is a JSON array of objects
api.rows.add(data).draw();
Sorry I do not get it:-(
Could you please do me a favor: take my JSON object and create a jsfiddle working sample?
Could you please refer to your test case - i would be glad to take a look at your code.
Hi,
All I need is to consume the JSON object I wrote in my original question so that the data" part is rendered as a datatable. Thanks.
var my_data = {"status":"success","data":[{"club_code":"3P","club_id":"1020001","club_name":"STAGE ROBERT DAL FARRA"},{"club_code":"6D","club_id":"1020002","club_name":"BRIDGE VOYAGES SUD OUEST"},{"club_code":"1-","club_id":"1020003","club_name":"STAGE FRANCK BUSSELIER"}]};
$('#example').DataTable( {
data: my_data.data
} );
Working! You're awesome :-)