Looping through an array of json objects

Looping through an array of json objects

sadepusadepu Posts: 1Questions: 0Answers: 0
edited April 2014 in DataTables 1.9
I have JSON object returned by AJAX call like below

{
"aaData":[
{"type":"type1","ratings":[
{"date":"01-Jul-2013","rating":"A","ratingType":"FLT"},
{"date":"02-Jul-2013","rating":"B","ratingType":"LLT"},
{"date":"03-Jul-2013","rating":"C","ratingType":"MLT"},
{"date":"04-Jul-2013","rating":"D","ratingType":"NLT"}]},

{"type":"type2","ratings": [

{"date":"05-Jul-2013","rating":"AA","ratingType":"RT1"},
{"date":"06-Jul-2013","rating":"BB","ratingType":"RT2"},
{"date":"07-Jul-2013","rating":"CC","ratingType":"RT3"},
{"date":"08-Jul-2013","rating":"DD","ratingType":"RT4"}]}
]
}

I need to draw the data table like below using the above JSON object. JSON object may have n number of types.

type1
Date Rating Rating Type
1-Jul-13 A FLT
2-Jul-13 B LLT
3-Jul-13 C MLT
4-Jul-13 D NLT
type2
Date Rating Rating Type
5-Jul-13 AA RT1
6-Jul-13 BB RT2
7-Jul-13 CC RT3
8-Jul-13 DD RT4

Please let me know how to loop the above JSON object and display the columns.

Replies

  • allanallan Posts: 63,493Questions: 1Answers: 10,470 Site admin
    DataTables currently doesn't do nested data. You would need to flatten your array / object structure.

    Allan
This discussion has been closed.