Ajax server-side data
Ajax server-side data

Hi,
I use server-side datatables with ajax.I get data without problem.
The data from the server is like this:
data: [
0: {
id: 35
name: "myname lastname"
created_at: "2020-12-20T21:28:41.000000Z"
photos: [
0: {
file_name: "img_001.jpg"
folder_name: "avatars"
}
1: {
file_name: "img_002.jpg"
folder_name: "avatars"
}
]
}
1: {
// similar with data(0)
}
]
datatables configurations:
columns: [
{
data: 'name', // it displayed in the table.
},
{
data: 'photos.0.file_name' // it displayed in the table.
},
{
data: null,
render: function (data, type, row) {
let path = row['photos.0.folder_name'] + row['photos.0.file_name'];
return path; // it doesn't work. Nothing show up
}
]
How can I display file_name and folder_name at render level?
Thanks
This discussion has been closed.
Answers
Its an array of objects. You can loop through the array and build an HTML string that you return after the loop.
EDIT: You would loop through
row.photos
.Kevin
I am a beginner at js. I have googled it, but i couldnt find any object loop for my problem.
Could you send me any link? or just write how can I do this:
never mind. I have already solved it.
row.photos[0].file_name
So simple!