JSON -> "No data available in table"
JSON -> "No data available in table"
Hey everyone,
I've checked all the examples and help in the forums, but unfortunately I could not get my issue resolved. Maybe someone here can help me, would really appreciate it.
The table is just empty, and it displays that "no data is available in the table".
I'm getting JSON from a txt file, I have validated the JSON that's in there with jsonlint.com.
I have also verified with Firebug, that I'm receiving the JSON data within the script.
My assumption is, that I'm missing a parameter within the datatable script - any idea?
My JavaScript:
$(document).ready(function() {$('#example').dataTable( {
"sAjaxSource": "../protected/controller/data.txt", "sAjaxDataProp":"", "columns": [ { "mDataProp": "ID", "title": "ID" }, { "mDataProp": "Name", "title": "Name" }, { "mDataProp": "Name_ext", "title": "External Name" }, { "mDataProp": "Mail", "title": "E-Mail" }, { "mDataProp": "BG_ID", "title": "BackID" }, { "mDataProp": "LLOG", "title": "Live-Log" }, { "mDataProp": "RHASH", "title": "Read-Hash" }, { "mDataProp": "USRN", "title": "User-RN" }, { "mDataProp": "USPW", "title": "User-PW" } ],
} );
});
- My HTML:
- My JSON:
{
"users": [
{
"ID": "1",
"Name": "Lorem",
"Name_ext": "Ipsum",
"Mail": "smo@localdmn",
"BG_ID": "1",
"LLOG": "ea rebum",
"RHASH": "$ujjud345",
"USRN": "diam nonumy",
"USPW": "Lorem Ipsum"
},
{
"ID": "2",
"Name": "Lorem",
"Name_ext": "Ipsum",
"Mail": "smo@localdmn",
"BG_ID": "1",
"LLOG": "ea rebum",
"RHASH": "$ujjud345",
"USRN": "diam nonumy",
"USPW": "Lorem Ipsum"
},
{
"ID": "3",
"Name": "Lorem",
"Name_ext": "Ipsum",
"Mail": "smo@localdmn",
"BG_ID": "1",
"LLOG": "ea rebum",
"RHASH": "$ujjud345",
"USRN": "diam nonumy",
"USPW": "Lorem Ipsum"
}
]
}
Thanks for any hints!
Best regards,
Stephan
This question has an accepted answers - jump to answer
Answers
First,
If you are using Datatables 1.10 you are using the wrong options "sAdjaxSource" for example. If your using 1.9.x then ignore this and move to #2 below....
Second (and more important),
Your JSON is not formatted correctly. See this example for fomatting: http://datatables.net/examples/ajax/objects.html
Hi Daimian,
Thanks for your quick reply! I am indeed using Datatables 1.10, so I have changed it to just "ajax" now, this did not bring any change though.
Also, I don't see how my JSON is formatted incorrectly. I have compared every line to the example you mentioned, and I do not see any issues.
Here is a better view at my JSON code:
http://pastebin.com/t94G0rLD
Many thanks,
Stephan
Your JSON must be in this type of format:
Ahhh Alright, it specifically has to be "data" and cannot be e.g. "users".
Thanks man, sometimes it's really the small things that keep you up all night :-).
No problem :)
Sometimes you just need to talk it through with someone to realize what you overlooked.