How to get "data" into the serialized json string
How to get "data" into the serialized json string
CoolinJack
Posts: 4Questions: 2Answers: 0
Here is the example of my aspx page
<script type="text/javascript">
$(document).ready(function () {
$('#players').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "ServerSideProcessing.aspx",
"type": "POST",
"dataType": "JSON",
"dataSrc": "data",
"columns": [
{ "data": "ID" },
{ "data": "TeamID" },
{ "data": "TeamName" },
{ "data": "pno" },
{ "data": "PlayerName" },
{ "data": "Games" },
{ "data": "Goals" },
{ "data": "Assists" },
{ "data": "Points" },
{ "data": "Pens" },
{ "data": "Misc" }
]
}
});
});
</script>
Valid Json Example:
[{
"ID": "3",
"teamid": "1",
"TeamName": "Team 1",
"pno": "3",
"PlayerName": "Player 1",
"Games": "2",
"Goals": "3",
"Assists": "4",
"Points": "5",
"Pens": "8",
"Misc": "7"
}]
How do I get the "data" Header into the json string ?
{
"data": [ <<<<<<<<<<
{
"name": "Tiger Nixon",
"position": "System Architect",
"salary": "$320,800",
"start_date": "2011/04/25",
"office": "Edinburgh",
"extn": "5421"
},
...
]
}
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide!
This discussion has been closed.
Answers
You don't have to do that but to do so is specific to the language you are using for your server. Instead you can use
ajax.dataSrc
with an empty string. See below code.You have defined your
columns
inside theajax
config option which isn't going to work. Based on the JSON snippet you provided you aren't using server side processing as it looks like the response doesn't have the parameters discussed in the SSP docs. Try this code:The
columns.data
strings are case sensitive. You have{ "data": "TeamID" },
but your JSON response has"teamid": "1",
. The case needs to match.Kevin
Hi Kevin
Many thanks for those pointers, it will help me to get a working solution !.
I though it might be of help if I included all My Code !, as It would help someone in the same situation
I have read the requirements of the values that would be required in the json reponse, for ssp, so I though I would share with you how I have created my json.
Step 1: A Datatable is Filled using a MSQL Stored Procedure.
Step 2: A New DataTable is Created with all the correct columns and Data
Step 3: The Datatable is Serialized then returned to the calling web page