AJAX Source aaData and sAJAXDataProp

AJAX Source aaData and sAJAXDataProp

SPRSPR Posts: 2Questions: 0Answers: 0
edited January 2014 in General
Hello @ all,

I need to solve a problem with server-side filtering and paging. The data I receive i formatted in JSON and it looks like that:

{
"METADATA" : {
"TOTAL" : 116,
"SELF-LINK" : "/rest/psi/releases",
"PARAMETERS" : [
{
"DB_NAME" : "PARAM1",
"INFO1" : "value",
"INFO2" : "value",
"LINK" : 1
},
{
"DB_NAME" : "PARAM2",
"INFO1" : "value",
"INFO2" : "value",
"LINK" : 1
},
{
"DB_NAME" : "PARAM3",
"INFO1" : "value",
"INFO2" : "value",
"LINK" : 0
}
],
"TIMESTAMP" : "none"
},
"DATA" : [
{
"LINKS" : {
"link1" : "/placeholder/placeholder/placeholder/placeholder",
"link2" : "/placeholder/placeholder/placeholder/placeholder"
},
"GRANTS" : [
"UPDATE",
"DELETE"
],
"VALUES" : {
"PARAM1" : "value",
"PARAM2" : "value",
"PARAM3" : "value"
}
},
{
"LINKS" : {
"link1" : "/placeholder/placeholder/placeholder/placeholder",
"link2" : "/placeholder/placeholder/placeholder/placeholder"
},
"GRANTS" : [
"UPDATE",
"DELETE"
],
"VALUES" : {
"PARAM1" : "value",
"PARAM2" : "value",
"PARAM3" : "value"
}
}
}
]
}

As far as I know, I need to use aaData and / or sAJAXDataProp to solve this problem. As you can see METADATA and DATA are on the same Level of the JSON data, but I dont know how to add this in DataTable by using sAJAXDataProp or aaData. If I am using aaData I need to add it to the JSON Data and it would look like this:

aaData : [
METADATA: {
...
},
DATA: {
...
}
]

I think I would rather using sAJAXDataProp, but then I need to add METADATA and DATA to it, but I dont know how.
Would it be something like this?

"sAjaxDataProp": ["METADATA", "DATA"]

I appreciate every help,

thanks in advance

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    DataTables currently assumes that the information required for each row in the table will be contained in an array element. You would need to transform your data into a simple array, rather than two arrays, to have this working in DataTables as it currently stands. I might relax this in future, but that's how it is just now.

    Allan
  • SPRSPR Posts: 2Questions: 0Answers: 0
    Thanks for your answer!

    Is it possible to solve this problem by using Ajax Source and fnServerData? I just read something about it? Sorry for bothering you.
    Or is fnServerData also expecting a 2D array?

    Thanks again
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    In 1.9 you would need to use fnServerData to make your Ajax call and then manipulate the data into a single array.

    Allan
This discussion has been closed.