JSON SubArray Columm

JSON SubArray Columm

rainolfrainolf Posts: 56Questions: 6Answers: 0
edited October 2013 in DataTables 1.9
Hi,
i'm trying to display my data using server side php script.
My data comes to my Data Table in json with subarray inside like:

{
"iTotalDisplayRecords":"271",
"iTotalRecords":"273",
"sEcho":0,
"aaData":[
{"payroll_number":"001","employee_id":"2","employee_name":"John Doe","company":"MY COMPANY,"city":"MY CITY",
"leaves":[{"LTY001":"11.88"},{"LTY002":"26.13"}],
"timesheets":[{"punch_in_user_time":"2013-08-29 12:41:23","punch_in_note":"IN"}]
]
}

In my client code i've write something like:
"aoColumns": [
{ "mDataProp": "payroll_number", "iDataSort": 2, "sClass": "test", "sWidth":"50px"},
{ "mDataProp": "employee_name", "bVisible": true, "sClass": "test", "sWidth":"200px" },
{ "mDataProp": "company" ,"sClass": "test","sWidth":"100px" },
{ "mDataProp": "city","sClass": "test" },

]
and it works fine.

I need now to add additional colums where it belongs to a subarray like leaves or timesheets.

Could someone point me on the right way?

Thank you

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    You can access the array information using Javascript dotted notation in your mDataProp: `timesheets.0.punch_in_user_time` for example. Or you can have DataTables show the information from all array elements if there might not be exactly one item: `timesheets[, ].punch_in_user_time` where the `, ` is what will separate the data when displayed.

    Allan
  • rainolfrainolf Posts: 56Questions: 6Answers: 0
    Thank you Allan.
This discussion has been closed.