我无法在数据表中动态声明表头。这是我到目前为止尝试过的:
if (result != "[]") {
var resultColumns = [];
$.each(result.Columns, function(i, value){
var obj = { sTitle: value };
resultColumns.push(obj);
});
$('#trendingTable').dataTable({
"aaData": result,
//important -- headers of the json
"aoColumns": [ resultColumns ],
"sPaginationType": "full_numbers",
"aaSorting": [[0, "asc"]],
"bJQueryUI": true,
"bDestroy": true,
});
}
我的 JSON 结果:
{"Column1":["ABC","XYZ"],"Column2":[0.0,0.0],"Colum3":[0.0,0.0],,"Columns":["Column1","Column2","Colum3"]}