Accessing nested array of objects from dataTable row
Accessing nested array of objects from dataTable row
I have an api response of data that im using to populate my table. the data looks like this:
{
code: 'CPX154',
identity: '108',
name: 'Joshua Laryea',
created_at: '12:23 pm',
phone: '0559546287',
pickup: [
{desc: 'Shirts', quantity: '15'},
{desc: 'Suit', quantity: '2'},
{desc: 'Jeans', quantity: '6'}
]
},
{
code: 'CGH154',
identity: '108',
name: 'Gloria Fynn',
created_at: '15:23 pm',
phone: '0249563287',
pickup: [
{desc: 'Shirts', quantity: '5'},
{desc: 'Trouser', quantity: '2'},
{desc: 'Shorts', quantity: '1'},
{desc: 'Suit', quantity: '2'},
{desc: 'Jeans', quantity: '6'}
]
}
After doing a JSON.parse(data)
i am able to access the data like any other normal object and have used it to populate the datatable. My issue is that on click of any of the table row, when i get access to that row's data the field 'pickup' shows [object object] and i cannot parse it with JSON also. it results in an error.
please help
Answers
Maybe this example will help:
https://datatables.net/examples/ajax/deep.html
Without seeing your Datatables init code its difficult to help move you in the right direction.
Kevin
this is my init code
One option is to use
columns.render
to loop through thepickup
array and append each object to a string that will be returned from the function for display.Is the question you have around editing the field? Maybe bubble editing would be a good option?
https://editor.datatables.net/examples/bubble-editing/index.html
Kevin