I have a DataTable, where in I want to have a dropdown which has a list of the columns names of the DataTable with checkboxes. Based on the selections in the checkbox, the DataTable should be updated with only those columns. Here is my JsFiddle tryin to achieve the same.
HTML:
<div class="button-group">
<button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-cog"></span> Modify Columns</button>
<ul class="dropdown-menu" id="checkboxlist"></ul>
</div>
<table id="example" class="display" cellspacing="0" width="100%"></table>
JavaScript:
AList = ["A", "B"];
var selected = [];
var sortlist = [];
for (var i = 0; i < header.length; i++) {
AList.push(header[i]);
}
$('#example').append("<thead style='background-color: rgb(159, 191, 223); !important'><tr></tr></thead>");
for (var i = 0; i < AList.length; i++) {
$('#example thead tr').append("<th style='background-color: rgb(159, 191, 223); !important'>" + AList[i] + "</th>");
$('#checkboxlist').append(' <li><a href="#" class="small" data-value="'+AList[i]+'" tabindex="-1"><input type="checkbox" />' +AList[i] + '</a></li>')
}
$('#example').append("<tbody></tbody>");
$('#checkboxlist').append('<li><button type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown"> Update</button></li>');
Any suggestions on how to go about this?