Populate Data into Columns of Datatables
Populate Data into Columns of Datatables
Hi,
I am getting a json object response from the server but unable to render the data into columns.
Appreciate your help.
JSON OBJECT RESPONSE:
{
"CHD2": {
"POSName": "CHANDIGARH INDU. AREA-I",
"HODB": "QSR_PHASE-I_CHANDIGARH"
},
"D002": {
"POSName": "DEHRADUN-ASTLEY HALL",
"HODB": "QSR_DEHRADUN_ASTLEY"
},
"J002": {
"POSName": "VAISHALI NAGAR",
"HODB": "QSR_VAISHALI_NAGAR"
}
}
JQUERY SCRIPT
<script>
$(document).ready(function() {
console.log('Initializing tables...');
var aaData = [];
$('#dataTables-example').DataTable({
responsive: true,
processing: true,
serverSide: true,
data : aaData,
ajax: {
url:'http://localhost:81/reporting/outletList.php',
type:'POST',
dataType:'json',
dataSrc : "",
error: function(errorThrown){
alert(errorThrown);
alert("There is an error with AJAX!");
},
"success": function(data) {
console.log(data);
aaData.push([
data['CHD2'].POSName,
data['CHD2'].HODB
]);
aaData.push([
data['D002'].POSName,
data['D002'].HODB
]);
data = aaData;
console.log(data);
}},
/*columns: [
{ data: "POSName"},
{ data: "HODB"}
],*/
"language": {
"zeroRecords": "No records to display"
}
})
});
</script>
Still it's not working. JSON Object response is there in the developer tool of Chrome but data is not getting populated in the table.