how to form dataTable with object of array of objects

how to form dataTable with object of array of objects

mahendraonterumahendraonteru Posts: 2Questions: 2Answers: 0

hera my sample json:

{
"sites": [
{
"status": "active",
"id": 1,
"name": "Default Site",
"description": "Default Site",
"customfields": [
{
"value": "",
"options": "Value1,Value2",
"fieldid": 3,
"fieldname": "Site Custom Field1"
},
{
"value": "",
"options": "v1,v2,v3",
"fieldid": 4,
"fieldname": "CUSTOM FIELDS"
},
{
"value": "",
"options": "1,3,4,5,6",
"fieldid": 10,
"fieldname": "zone"
}
],
"alias": "DS1"
},
{
"status": "active",
"id": 2,
"name": "Site1",
"description": "Site1",
"customfields": [
{
"value": "Value2",
"options": "Value1,Value2",
"fieldid": 3,
"fieldname": "Site Custom Field1"
},
{
"value": "",
"options": "v1,v2,v3",
"fieldid": 4,
"fieldname": "CUSTOM FIELDS"
},
{
"value": "",
"options": "1,3,4,5,6",
"fieldid": 10,
"fieldname": "zone"
}
],
"alias": "SIT"
}
]
}

my javascript code:
/// where items are response.sites

function generateTableData( items) {

 $('#myTableId').dataTable({

"bDestroy": true, responsive: true,
data: items,
"columns": [
{"data": "id", "title": "ID", "visible": false},
{"data": "name", "title": "Name"},
{"data": "alias", "title": "Alias"},
{"data": "description", "title": "Description"},
{"data": "customfields[0].value", "title": "customfields[0].fieldname"},
{"data": "customfields[1].value", "title": "customfields[1].fieldname"},
{"data": "customfields[2].value", "title": "customfields[2].fieldname"},
{"data": "customfields[3].value", "title": "customfields[3].fieldname"},
{"data": "customfields[4].value", "title": "customfields[4].fieldname"}

    ]
});
$('#myTableId').removeClass('display').addClass('table');

}

the customfields are not adding.please help me

This discussion has been closed.