Add Dynamic columns to datatable
Add Dynamic columns to datatable
robss21
Posts: 1Questions: 1Answers: 0
Hi,
I want to add dynamic drop down list columns in jquery datatables
This 1,2,3,4 I given for demo purpose: Otherwise it maycome from 1 to 31 based on month and year, which user has chosen.
It is showing as No data in table
Code:
HTML
<table id="myGridAttendance" class="table compact" style="font-size:12px" width="100%">
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</thead>
</table>
Jquery
<script type="text/javascript">
$(document).ready(function () {
var month1 = $('#id_ddlMonth').val();
var year1 = $('#id_ddlYear').val();
var aryColTableChecked = ["1", "2", "3", "4"];
var aryJSONColTable = [];
for (var i = 0; i < aryColTableChecked.length; i++) {
aryJSONColTable.push({
"mData": aryColTableChecked[i],
"aTargets": [i],
"mRender": function (data, type, full) { return "'<select id=ddlAttandnce" + i + ">' + '<option value='0'>--Select--</option>' + '<option value='P'>Present</option>' + '<option value='A'>Absent</option>" }
});
// alert(aryJSONColTable[i]["mRender"]);
};
$('#myGridAttendance').DataTable({
"ajax": {
"url": '@Url.Action("GetAttendanceTable", "Messenger")',
"dataSrc": "",
"data": {
month: month1,
year: year1
},
},
"columns": aryJSONColTable,
"bDestroy": true
});
});
</script>
Please Help..
This discussion has been closed.