I am using datatables and responsive extension, I've got some checkboxs which represent boolean data (0 , 1) in my db. I use rowCallback
data
to check the checkbox. But when the page is resized or it is in responsive mode it shows column as child, detailed list, the checkbox is not checked and rowCallback
not triggered and data is undefined..!
table=$('#mytable').DataTable({
"sDom": "<'row DTTTHeader'<'col-sm-7'Tl><'col-sm-5 no-padding'f>>t<'row DTTTFooter'<'col-sm-6'i><'col-sm-6'p>>",
processing: true,
serverSide: false,
deferRender: true,
responsive: true,
ajax: {
url: '/my/url/show',
method: 'POST',
},
columns: [
{data: "id", searchable: false, visible: false, className: "never"},
{data: "product", searchable: true, visible: true},
{data: "category", searchable: true, visible: true},
{data: "available", searchable: true, visible: true},
{data: "sold", searchable: true, visible: true},
{data: "active", searchable: false,
render: function ( data, type, row ) {
if ( type === 'display' ) {
return '<label><input class="checkbox colored-danger active" type="checkbox" disabled><span class="text"></span></label>';
}
return data;
},
className: "dt-center"
}
{
data: null,
defaultContent: '<button class="btn btn-info btn-xs edit"><i class="fa fa-edit"></i> edit</button> <button class="btn btn-danger btn-xs del" data-toggle="modal" data-target="#modal-danger"><i class="fa fa-trash-o"></i> remove</button>',
targets: -1 ,
searchable: false,
orderable: false,
}
],
rowCallback: function ( row, data ) {
$('input.active', row).prop( 'checked', data.active == 1 );
}
});
buttons and checkboxs aren't working due to undefined row data.id
and data.active
Aucun commentaire:
Enregistrer un commentaire