Server Side Processing with deep array data

Server Side Processing with deep array data

nitin88nitin88 Posts: 6Questions: 0Answers: 0
edited December 2013 in DataTables 1.9
Hi,

I am trying to use Server Side Processing for the Datatables.

However I am unable to show the results due to complex JSON data structure [or I am not finding how to show it]

Here's the sample JSON data that is being sent from the Server.
[code]
{
"sEcho": "1",
"iTotalRecords": 10,
"iTotalDisplayRecords": 5,
"aaData": {
"records": [
{
"attributes": {
"P_Close_Time": "1376493600",
"P_Description": "Test1"
},
"recordId": "6277988",
"url": "localhost:8888/search-engine/v1/search?recordId=6277985",
"aggregationCount": 0
},
{
"attributes": {
"P_Close_Time": "1376493600",
"P_Description": "Test2"
},
"recordId": "6277988",
"url": "localhost:8888/search-engine/v1/search?recordId=6277986",
"aggregationCount": 0
},
{
"attributes": {
"P_Close_Time": "1376493600",
"P_Description": "Test3"
},
"recordId": "6277988",
"url": "localhost:8888/search-engine/v1/search?recordId=6277987",
"aggregationCount": 0
},
{
"attributes": {
"P_Close_Time": "1376493600",
"P_Description": "Test4"
},
"recordId": "6277988",
"url": "localhost:8888/search-engine/v1/search?recordId=6277988",
"aggregationCount": 0
},
{
"attributes": {
"P_Close_Time": "1376493600",
"P_Description": "Test5"
},
"recordId": "6277988",
"url": "localhost:8888/search-engine/v1/search?recordId=6277989",
"aggregationCount": 0
}
]
}
}
[/code]


and this is my code
[code]
$('#example').dataTable({
"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page"
},
"bProcessing" : true,
"bServerSide" : true,
"sAjaxSource" : "<%=dataresourceURL%>",
"aoColumns": [
{ "mData": "records.attributes.P_Close_Time" },
{ "mData": "records.attributes.P_Description" },
{ "mData": "records.url" }
]
});
[/code]

But I am unable to do it!
Could you please suggest how to get those items in the table.

Replies

  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    aaData is not an array in your above code. Do you want it to be? DataTables expects it to be. Otherwise you could use sAjaxDataProp to tell DataTables to use `aaData.records` as the data source array.

    Allan
  • nitin88nitin88 Posts: 6Questions: 0Answers: 0
    wow.. that works without an issue. thanks lot. great support
  • nitin88nitin88 Posts: 6Questions: 0Answers: 0
    one quick question, assume I am using local variable/data for data tables which contains JSON data with special characters and lot more unexpected special characters,

    how do I use that data to show records, because the below code is throwing error when it encounters some special characters
    [code]
    "aaData": "${jsonResult.records}",
    [/code]
  • allanallan Posts: 63,494Questions: 1Answers: 10,470 Site admin
    I'd need to see an example to understand what is going wrong I think.

    Allan
This discussion has been closed.