convert boolean to checkbox datatable jquery code example
Example 1: datatables boolean column checkbox
$('#frm-example').on('submit', function(e){
var form = this;
table.$('input[type="checkbox"]').each(function(){
if(!$.contains(document, this)){
if(this.checked){
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', this.name)
.val(this.value)
);
}
}
});
});
Example 2: datatables boolean column checkbox
var simple_checkbox = function ( data, type, full, meta ) {
var is_checked = data == true ? "checked" : "";
return '<input type="checkbox" class="checkbox" ' +
is_checked + ' />';
}
var setup_datatable = function () {
$('#data-table').DataTable({
"columns": [
{ "data": "id", "className": "text-center"},
{ "data": "keywords"},
{ "data": "platform"},
{ "data": "is_active", "render": simple_checkbox},
{ "data": "is_terminated", "render": simple_checkbox}
],
"ajax": "/data"
});
}