Dynamic title column by dataSrc
Dynamic title column by dataSrc
Hi
I been working on a feature which the titles has to be dynamic created . The titles depends what data return from the server. I tried to set the data for aoColumns in dataSrc funtion ,but i kept running into aDataSort of undefined. Couldn't even debugger in the function.
Is any way that i can dynamic the titles?
data from server side
data:[{
couponName:'CType1',
couponPrice:'1000',
paymentId:'111111-111111-111111',
SignupUserInfoList:[
{ columnName:'Name',columnValue:'Peter'},
{ columnName:'Number',columnValue:'0978123456'},
{ columnName:'Email',columnValue:'Peter123@gmail.com'}],
}]
reset data in dataSrc function
columns=[
{ sTitle:'Name',mData:'Peter'},
{ sTitle:'Number',mData:'0978123456'},
{ sTitle:'Email',mData:'Peter123@gmail.com'}],
]
<table id="displayTable" class="table table-bordered table-hover" width="100%"></table>
$('displayTable').dataTable({
"language": cn_dataTable,
"destroy": true,
"autoWidth": true,
"searching": false,
"serverSide": true,
"processing": true,
"bSort": false,
"sAjaxDataProp": "columnDatas",
"ajax": {
"url": " ",
"type": "POST",
"dataSrc": function (json) {
if (json.data.length > 0) {
var cValue = '';
for (var x = 0; x < json.data.length; x++) {
if (json.data[x].SignupUserInfoList.length > 0) {
var sLength = json.data[x].SignupUserInfoList.length;
for (var y = 0; y < sLength; y++) {
var title = json.data[x].SignupUserInfoList[y].columnName;
var value = json.data[x].SignupUserInfoList[y].columnValue;
column = { "sTitle": title , "mData": title},
columns.push(column);
columnDatas.push(value);
}
dataSet.push(columnDatas);
}
}
}
return columnDatas;
},
"data": { oNo: "" }
},
"aoColumns": column,
"aaData": columnDatas
})
Thank you