Checkbox first column
Checkbox first column
Hello, I would like to get a checkbox at the first column. And also a checkbox that select all. I found this example: https://www.gyrocode.com/articles/jquery-datatables-how-to-add-a-checkbox-column/
But I have difficulties how to implement into my code. I need som help from you!
My code look like:
// Data received from php
var data = JSON.parse(xhr.responseText);
// Deleate table
if ($.fn.DataTable.isDataTable('#example')) {
    $('#example').DataTable().destroy();
    $('#example').removeClass('dtr-inline collapsed');
}
var columns = [];
columnNames = Object.keys(data[0]);
for (var i in columnNames) {
     columns.push({data: columnNames[i],
                title: columnNames[i] + '\xa0'});
}
table = $('#example').DataTable( {
        pagingType: "simple_numbers",
        orderCellsTop: true,
        ordering: true,
        dom: 'trp',
        scrollX: true,
        lengthMenu: [ 10, 25, 50, 75, 100, 500, 50000],
        data: data,
        columns: columns
} );
This question has accepted answers - jump to:

Answers
To start with you will need to add the first column code manually. Instead of starting with an empty columns array, ie
var columns = [];, do something like this:KEvin
Thanks kthorngren! I mange to get the checkboxes working. I got more more issue. The code below works to check which checkboxes is checked. But if I reorder I get the wrong value.
I found this example from you kthorngren:
http://live.datatables.net/mutavegi/1/edit
Excaty what I want expect that if Ifilter I get checkboxes that does not show (if they are checked before they are fitered away).
Is that possible to modify with this exampe?
You can use the
selector-modifierto limit the rows to those on the page{page: 'current'}or those visible after searching{search: 'applied}`.Kevin
Thanks again kthorngren !
Here how to make it for somebody else: