Table not loading with returned data
Table not loading with returned data
First, thanks, I am really enjoying this compared to .net grid, BUT...
After finally getting past the Invalid JSON error, table wont show data... Using your suggested debug method returned data is
{"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"}]}
My script is:
$(document).ready(function () {
//$('#example').DataTable({ "ajax": "data/arrays.txt" });
$('#example').DataTable({
'ajax':{
'url': 'default.aspx/GetDataTablesTestData',
//'dataSrc': 'd',
//"sAjaxDataProp": "d",
'type': 'POST',
'contentType': 'application/json; charset=utf-8',
'dataType': 'json'
}
});
});
Any help would be greatly appreciated.
This question has an accepted answers - jump to answer
Answers
It looks like your data source is
d
instead of the normaldata
. I think if you uncomment the line'dataSrc': 'd',
it will load the data object usingd
.Kevin
Thx for the follow-up K, but...
As you can see I commented it out, tried it and event (as you suggested), changed the d to data, still no joy.
{"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"},{"Name":"Airi Satou","Position":"Accountant","Office":"Tokyo","Extn":"5407","Start date":"2008/11/28","Salary":"$162,700"}]}
I'm posting this JSON, because there is clearly some concept about server-side retrieval I have yet to grasp. This is the JASON return, but what exactly is datatables expecting. I can read/interpret and display this just fine outside of ...
Maybe you need to define the columns using
columns.data
.Kevin
Nothing yet. kind of frustrating, no errors, no display of what appears to be valid JSON.
My script, just in case I'm not using your suggestion correctly:
$(document).ready(function () {
//$('#example').DataTable({ "ajax": "data/arrays.txt" });
$('#example').DataTable({
ajax:{
url: 'default.aspx/GetDataTablesTestData',
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json'
},
dataSrc: 'd',
columns: [{'d':'Name'},{'d':'Position'}]
});
});
My HTML (just the table and surrounding div):
...and according to chrome, network response
{"d":[{"Name":"Tiger Nixon","Position":"System Architect","Office":"Edinburgh","Extn":"5421","Start date":"2011/04/25","Salary":"$320,800"},{"Name":"Airi Satou","Position":"Accountant","Office":"Tokyo","Extn":"5407","Start date":"2008/11/28","Salary":"$162,700"}]}
Try changing your columns definition to:
columns: [{'data':'Name'},{'data':'Position'}]
Kevin
You are my newest and bestest friend!!!!
Thank you so MUCH, DUDE I was at a lost.
Seriously, nice job.