I have a datatable that has dynamic columns
<table id="dt_basic" width="100%" class="table table-striped table-bordered table-hover tableSearch">
<thead>
<tr>
@foreach (var item in Model.ColumnInfo) {
<th>@Html.Raw(@item.ColumnHeader) </th>
}
<th>Edit</th>
</tr>
</thead>
<tbody></tbody>
</table>
I want to set the column type and column class after the datatable is populated
var table = $('#dt_basic').dataTable({
"pagingType": "full_numbers",
"ajax": "@Url.Action("LoadResultGrid", "Verifications", new { id = Model.RunId })",
"deferRender": true,
"bProcessing": true,
"scrollX": "100%",
"columnDefs": [
{
"targets": [0],
"visible": false,
"searchable": false
},
{
"targets": [1],
"searchable": true,
"visible": true
}
]
});
Model.ColumnInfo is a List of objects with attributes: ColumnHeader, ColumnType, ColumnClass.
So I need to loop through the columns after the table has been created and match the column header to Model.ColumnInfo.ColumnHeader and then set the column type to the corresponding Model.ColumnInfo.ColumnType and the column class to the corresponding Model.ColumnInfo.CoulmnClass.
Any help would be appreciated. Thanks.