Server-side "No matching records found"
Server-side "No matching records found"
I've seen a few posts on this but none of them seemed to correspond to the issue I'm having.
Debug Link: http://debug.datatables.net/ibadom
I also ran jsonlint.com to make sure the json is valid, which it is.
I'm stuck on how to get the data to display in dataTables. From everything I can see I am getting a good response from the server-side script although the debugger tells me that there's 0 rows (therein is the problem). I have the appropriate number of columns in the ajax and html code matching the service-side script. This is the data generated by the server-side script:
{
"draw": 1,
"recordsTotal": 1,
"recordsFiltered": 1,
"data": {
"VendorID": "V0000051",
"Name": "STAPLES CONTRACT AND COMMERCIAL INC",
"Mnemonic": "CORPORATE",
"TermsDescription": "INV 2/30 NET 31",
"ActiveYn": "Y"
}
}
I don't get any other error messages so it seems fine. Can anyone suggest next steps to take?
Thank you!
This question has an accepted answers - jump to answer
Answers
Do you have the column data defined? You either need to reset your array keys before your return in the back end, or define them on the front end in the dataTables JS.
This in the JS:
Or this server side on your array of data:
Could it have anything to do with the fact that the response header "Content Type" is set to text/html? How can I change this and does it matter?
@ignignokt:
My javascript is as follows:
$(document).ready(function() {
$('#Test').dataTable( {
"processing": true,
"serverSide": true,
"ajax": "tableTestData.php",
"columns": [
{ "data": "VendorID" },
{ "data": "Name" },
{ "data": "Mnemonic" },
{ "data": "TermsDescription" },
{ "data": "ActiveYn" }
],
});
sorry about the formatting. This should be better:
Shouldn't the json reply have the array brackets around your object? That might matter.
IE:
instead.
I believe you'd just have to wrap your return for your data in an array to test that out.
If that isn't it, then I'm out of ideas for now.
yea I might have to look at the format of the json. I have data set to an object but it should probably be an array of objects like this data: [ { } ]
I'll give it a try and reformat my server-side script output.
@ignignokt:
reformatting the json as an array of objects does indeed work! Thanks for pointing me in the right direction.
No problem, glad that was it!