Can't fill in json to the datatable?

Can't fill in json to the datatable?

gron2gron2 Posts: 5Questions: 2Answers: 0

I have used ajax to get a json type data. The data is stored in a variable "msg" in ajax. How to write the code to fill in the "msg" to a datatable. The format of this json is like
{ "virtualTable": [ { "ID": "1", "FESTIVAL": "Antipodes Festival", "SUBURB": "Lonsdale Street, Melbourne", "POSTCODE": "3000", "WEBSITE": "http://www.antipodesfestival.com.au/", "DESCRIPTION": "The greek precinct in melbourne cbd will transform into a huge, free street festival with the hosting of the antipodes lonsdale street festival which will hold sway from 14 february 2015 to 15 february 2015." }, { "ID": "5", "FESTIVAL": "Boite Singers Festival", "SUBURB": "Victoria", "POSTCODE": "3000", "WEBSITE": "http://boite.com.au/index.php", "DESCRIPTION": "The boite singers festival brings you four days of vocal inspiration and sheer fun on the second weekend of january each year." } ] }

I could display the json data on the page but cannot show it in a datatable. I use ASP not PHP.
I have used almost all methods the website provided but still doesn't work. Hope someone to help me.
$('#eventtable').dataTable({ "sErrMode": "throw", "sServerMethod": "POST", "bDeferRender": true, "sScrollXInner": "100%", "bProcessing": true, //"data": msg.mData, //"dataSrc":data, //"ajax": "data/objects.txt", "aoColumns": [ { "mData": "ID" }, { "mdData": "FESTIVAL" }, { "mData": "SUBURB" }, { "mData": "POSTCODE" }, { "mData": "WEBSITE" }, { "mData": "DESCRIPTION" } ], "paging": false, "searching": false, "retrieve": true, "Processing": true, //"data": msg.data, //"datatype": "JSON" });

Answers

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Can you edit your post to wrap the code in the three tick marks so the formatting works?
    It looks like your data is coming back as an array of objects, so you need to look at these two examples and sort of combine the syntax. Debugging in the browser will let you test your code.

    http://datatables.net/examples/ajax/objects_subarrays.html

    http://datatables.net/examples/ajax/deep.html

  • gron2gron2 Posts: 5Questions: 2Answers: 0

    Sorry about the format. I have read all examples. The point is my json data is in a variable. Not in txt or url(php), I used newtonsoft.json to convert the data to json. There is one example has the same json format of mine, but it is not in a variable in ajax. So I do not know how to do with it.

This discussion has been closed.