I am trying to show a detectable in a modal box, which opens when user clicks a button. Although the data table is loading properly, but the problem is on check box selection. The Check all options on check box are not working on sometime. When I press escape button in modal then again open the model, the select all option of check box is working. Again I repeat this process, select all option is not working. How to solve it?
Script:
$(document).ready(function() {
var oTable = $('#order-listing').dataTable( {
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
},
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
select: {
style: 'multi',
selector: 'td:first-child'
},
lengthMenu: [[20,50, 100, -1], [20, 50, 100, "All"]],
pageLength: 20
} );
var allPages = oTable.fnGetNodes();
$('body').on('click', '#selectAll', function () {
if ($(this).hasClass('allChecked')) {
$('input[type="checkbox"]', allPages).prop('checked', false);
} else {
$('input[type="checkbox"]', allPages).prop('checked', true);
}
$(this).toggleClass('allChecked');
});
} );