jQuery Datatable unable to feed json into the table

This is the format of the json that I have received as a reponse from the django backend. How can I make datatable read this into the table?

[{
    "model": "model name", 
       "pk": 2, 
   "fields": {
         "name1": .., 
         "name2": ..,
         }
  },
  {
    "model": "model name", 
       "pk": 2, 
   "fields": {
         "name1": .., 
         "name2": ..,
         }
  }
]

Javascript:

    $(document).ready( function () {
            $('#tablename')
            .on('xhr.dt', function(e, settings, json){
                console.log(json)
            })
            .DataTable({
                "ajax": {
                    "url": "list",
                    "dataSrc": "",
                },
            });
    });

The console.log(json) prints the json as a string instead of a JS object.


Source: ajax

Leave a Reply