JSON object as a datasource without AJAX

JSON object as a datasource without AJAX

frSurferfrSurfer 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

Answers

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2

    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();

  • frSurferfrSurfer Posts: 7Questions: 3Answers: 0

    Sorry I do not get it:-(

    Could you please do me a favor: take my JSON object and create a jsfiddle working sample?

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2

    Could you please refer to your test case - i would be glad to take a look at your code.

  • frSurferfrSurfer Posts: 7Questions: 3Answers: 0

    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.

  • sameeralikhansameeralikhan Posts: 17Questions: 1Answers: 2
    Answer ✓

    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
    } );

  • frSurferfrSurfer Posts: 7Questions: 3Answers: 0

    Working! You're awesome :-)

This discussion has been closed.