Unable to upgrade to 1.10.x, using JSON datasource
Unable to upgrade to 1.10.x, using JSON datasource
I have an older DataTable that's been running fine for a couple years. I tried to clone it and upgrade to the new property names in 1.10.x. I can get the empty DataTable to display but no matter what I try, I cannot populate it with data.
I am using a c# webservice that returns a json string built via StringBuilder. It seems ugly and verbose as sin but in works in the 1.9.x world. I stripped it back so I am getting a simple json string back that looks like this:
{"d":"{\"data\": [ {\"barno\": \"012484\",\"name\": \"Lynn Eric Goar\",\"nameFirst\": \"Lynn Eric\",\"nameLast\": \"Goar\",\"companyFirm\": \"Law Office of Lynn Eric Goar PC\",\"address\": \"1955 W Grant Rd Ste 125 \",\"city\": \"Tucson\",\"state\": \"AZ\",\"zipCode\": \"85745-1481\",\"phone\": \"(520) 740-1447\",\"email\": \"lynn.goar@azbar.org\",\"registrations\": \"16100; 16101; 16102; 16103; 16116\",\"regDate\": \"1/25/2016 10:40:00 AM\"}]}"}
and my attempt to get the data:
"ajax": {
"url": "/services/admin/CLEbytheSea.asmx/getAllRegistrations",
"contentType": "application/json",
"type": "GET",
"data": function ( d ) {
return JSON.stringify(d);
}
},
What is wrong here? http://live.datatables.net/qesuyetu/1/edit
I've tried several methods of generating my json and have settled on one that creates clean json, exactly like the json that works in my legacy use of DataTables.
I just cannot get the 1.10.x version to read the json and populate the table.
This question has an accepted answers - jump to answer
Answers
moved to original post
The example you linked to doesn't work because there is no
data.d
property -data
is a string. Even worse,d
is a JSON encoded string inside the string! You would need to useJSON.parse( JSON.parse(data) ).d
.Likewise, if you are getting a string in the
d
property of the object (I've never understood why .NET does that) you might useajax.dataSrc
like this:Allan
Still throwing errors, different errors this time. I don't appear to have much control over .NET so it is what it is. I use this in my legacy version, with jQueryparseJSON, similar concept. But I cannot get anything to work in 1.10.x.
This is what I am trying to do with 1.10:
I got it working!
But I also have to specify the columns. For some reason columnDefs works in 1.9.x but in 1.10.x I have to use columns: