using deep nested data in child rows?

using deep nested data in child rows?

indymxindymx Posts: 63Questions: 3Answers: 0
edited March 2014 in DataTables 1.10
is this possible?

My data looks like this:

[code]

{
"data": [
{
"id": 30,
"customer": "Customer 3",
"shipper": "Company 2",
"consignee": "Company 3",
"tracking": "L353110",
"carrier": "Carrier 2",
"carrierPro": "327229",
"pickupTime": "02-28 23:02",
"deliveryTime": "02-21 07:02",
"nextUpdate": "03-02 14:03",
"status": "Scheduled",
"sendto": "terryg",
"contact": "dispatch / 555-555-1234",
"comments": [
{
"id": 62,
"load_id": 30,
"comment": "Delivered",
"update_time": null,
"updated_by": "terryg",
"miles": "123",
"localeta": "2014-02-12 18:00:27",
"location": "Columbus, OH"
}
]
}
]
}
[/code]

I've tried everything I can find on here as far as examples go to get this working. To no avail.

I'm building the child rows like you show in :

http://next.datatables.net/examples/api/row_details.html

I tried adding the lines that I'm having trouble with like this:

[code]
function format ( d ) {
// `d` is the original data object for the row
return ''+
''+
'Carrier'+
''+d.carrier+''+
'Contact'+
''+d.contact+''+
'Track / LID'+
''+d.tracking+''+
'Carrier Pro'+
''+d.carrierPro+''+
''+
''+
'Shipper'+
''+d.shipper+''+
'Consignee'+
''+d.consignee+''+
'Send Updates To'+
''+d.sendto+''+
' '+
''+d.update+''+
''+
''+
''+d.comments.location+''+
''+d.comments.comment+''+
''+d.comments.miles+''+
''+d.comments.localeta+''+
''+
''+
'Location'+
''+
'Miles Out'+
''+
'Local ETA'+
''+
'Comments'+
''+
''+
'';
}

[/code]


if I change the "d.comments.location" variable to "d.comments.0.location"

I get "Unexpected number".. leave out the 0 and I get "undefined"..

I'm really not clear on how I can get this json data displaying.

Replies

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin
    Comments is an array, so the fact that it is in a details row, doesn't really have much baring on how yo would access it - you would do it just like any other Javascript array: `d.comments[0].localeta` .

    Allan
  • indymxindymx Posts: 63Questions: 3Answers: 0
    edited March 2014
    Thanks!!!

    now to just loop thru that array and get all the data from it in the table.. (scratching head more)
  • indymxindymx Posts: 63Questions: 3Answers: 0
    edited March 2014
    added a little loop action and bam! it works..

    Thanks again for nudging me in the right direction here..

    [code]
    for (var i=0,len=d.comments.length; i
This discussion has been closed.