displaying nested JSON array

displaying nested JSON array

santoshjoshisantoshjoshi Posts: 3Questions: 0Answers: 0
edited March 2013 in DataTables 1.9
[code]
{
"Info": {
"VendorID": 1,
"HotelsInfo": [
{
"ID": 100,
"Name": "Test Hotel1",
"BookingInfo": [
{
"BookingDate": "2013-03-05"
}
]
},
{
"ID": 200,
"Name": "Test Hotel2",
"BookingInfo": [
{
"BookingDate": "2013-03-05"
},
{
"BookingDate": "2013-03-06"

}
]
},
{
"Name": "Test Hotel3",
"BookingInfo": [
{
"BookingDate": "2013-03-05"
},
{
"BookingDate": "2013-03-06"

},
{
"BookingDate": "2013-03-07"
}
]
}
]
},
"Status": true,
"Errors": null
}
[/code]
I want to view this like as shown below
---------------------------------
ID Hotel Name BookingDate
______________________________________
100 Test Hotel1 2013-03-05
200 Test Hotel2 2013-03-05
200 Test Hotel2 2013-03-06
300 Test Hotel3 2013-03-05
300 Test Hotel3 2013-03-06
300 Test Hotel3 2013-03-07
------------------------------------

I am using the below configuration, but this is somehow not working

[code]
$('#example').dataTable( {
"sDom": '<"toolbar">

Replies

  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    edited March 2013
    Doesn't quite work that way because you need to have one element in the array source for each row. At the moment you only have three. You'd need to alter the JSON data source to have 6 array entries if you want 6 entries in the table.

    Allan
  • santoshjoshisantoshjoshi Posts: 3Questions: 0Answers: 0
    Thanks Allan,

    I was thinking of altering the JSON, but thought there might exists a better solution with the forum.


    Regards,
  • allanallan Posts: 63,389Questions: 1Answers: 10,449 Site admin
    You could have it display three rows and use array syntax in mData to show the booking dates for each object on one line: `BookingInfo[, ].BookingDate` - would show it comma separated. But to show it over multiple rows would need multiple array entries in the top level array.

    Allan
  • santoshjoshisantoshjoshi Posts: 3Questions: 0Answers: 0
    Many thanks Allan,

    But my requirement is to show data over multiple rows.

    Regards,
This discussion has been closed.