I want to display the dynamic column header along with the results in datatable.In aaData and aoColumns attributes has to get result data and columns name from ajax call, Please suggest me how to do this or give me some alternate solution to get the dynamic data and column header from ajax call, Here is my code.:
var $table=$('#MSRRes').dataTable( {
"bFilter": false,
"bDestroy": true,
"bDeferRender": false,
"bJQueryUI": true,
"oTableTools": {
"sSwfPath": "swf/copy_cvs_xls_pdf.swf",
},
"sDom": 'TC<"clear">l<"toolbar">frtip',
"ajax" :{
url: 'getResult.php',
type: "POST",
data: {
formData:postData,
}
},
"aaData": results.DATA ,
"aoColumns": [ column_names ]
});
Here is my ajax call to get the result data and column names to be display:
$result=$afscpMsrMod->getAdvanceSearchResults($colCond,$whereCond,$having);
foreach($cols as $col) {
array_push($colArr, $colnames);
}
$colJson= json_encode($colArr);
$newarray = array(
"draw" => 1,
"recordsTotal" => sizeof($result),
"recordsFiltered" => sizeof($result),
"data" => $result,
"COLUMNS" => $colJson
);
echo json_encode($newarray);