The Jquery Code:
$(document).ready(function() {
var total = [];
$.ajax({
url: 'user.json',
dataType: 'json',
success: function(json) {
// get the `airport` array
var device = json.siteList;
var j = 1;
// loop through the array to populate your list
$.each(device, function(i, sites) {
// console.log(sites.siteName)
// $('#data_table').append("<tr>" + "<td>" + sites.siteName + "</td>" + "</tr>");
$.each(sites.deviceList, function(i, values) {
item = {}
item['siteName'] = sites.siteName;
item["deviceName"] = values.deviceName;
item["count"] = values.count;
total.push(item);
});
});
console.log(total);
$('#example').DataTable({
"aaData": total,
"aoColumns": [{
"sTitle": "siteName"
},
{
"sTitle": "deviceName"
},
{
"sTitle": "count"
},
]
});
}
});
});
The total variable output comes from user.json file where nested format json data is stored so i first converted it to normal json data and now i want to use it inside dataTable method The output of total variable is given below:
0: {siteName: "Site1", deviceName: "S1device1", count: "1"}
1: {siteName: "Site1", deviceName: "S1device2", count: "2"}
2: {siteName: "Site2", deviceName: "S2device1", count: "1"}
3: {siteName: "Site2", deviceName: "S2device2", count: "2"}
4: {siteName: "Site3", deviceName: "S3device1", count: "1"}
5: {siteName: "Site3", deviceName: "S3device2", count: "2"}
length: 6
Facing problem to use it please help me out, Any help will be highly appreciated , Thank you in advance..........