Example
Example below shows a data table using server-side processing mode where data is received from the server using Ajax.
$(document).ready(function (){
var table = $('#example').DataTable({
'processing': true,
'serverSide': true,
'ajax': '/lab/jquery-datatables-checkboxes/ids-arrays.php',
'columnDefs': [
{
'targets': 0,
'checkboxes': {
'selectRow': true
}
}
],
'select': {
'style': 'multi'
},
'order': [[1, 'asc']]
});
// Handle form submission event
$('#frm-example').on('submit', function(e){
var form = this;
var rows_selected = table.column(0).checkboxes.selected();
// Iterate over all selected checkboxes
$.each(rows_selected, function(index, rowId){
// Create a hidden element
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', 'id[]')
.val(rowId)
);
});
});
});
External resources used in this example: