gyrocode / jquery-datatables-checkboxes

Checkboxes is an extension for the jQuery DataTables library that provides universal solution for working with checkboxes in a table.
https://www.gyrocode.com/projects/jquery-datatables-checkboxes/
MIT License
150 stars 61 forks source link

Pagination selectAll error #99

Closed flanderboy closed 5 years ago

flanderboy commented 5 years ago

Hello everyone, I have a problem with my implementation of dataTable and Checkbox plugin. When the page is loaded and datatable draw is completed, i check "Select All" checkbox on the header and I see

console.log(dt.rows({selected: true}).indexes().length) = 20

but, if I go to page 2 I do not see rows selected and when I go back to page 1, the "Select All" checkbox on the header is unchecked.

If I reload the page, go directly to page 2 and back on page 1 and I click the "Select All" checkbox on the header, I See 20 (console.log) and if I go to page 2 all rows are selected.

Any idea

aoColumnDefs: [{
    aTargets: 0,
    checkboxes: {
        selectRow: true,
        selectAllRender: '<div class="checkbox"><input type="checkbox" class="dt-checkboxes"><label></label></div>'
    },
    mRender: function (data, type, row, meta) {

        data = '<div class="checkbox"><input type="checkbox" id="site_' + row.site_id + '" valie="' + row.site_id + '" class="dt-checkboxes"><label></label></div>';
        return data;

    },
    fnCreatedCell: function (td, data, rowData, row, col) {
        $(td).attr('data-site', rowData.site_id);
        this.api().cell(td).checkboxes.deselect(true);
    }
}],
select: {
    style: 'multi',
    selector: 'td:first-child'
},
mpryvkin commented 5 years ago

I suspect there might combination of two potential problems.

  1. You are deselecting checkboxes when cell is initially created with this.api().cell(td).checkboxes.deselect(true). If combined with other parameters, this may lead to effect you're describing.

  2. Make sure that the first column contains unique data. I see that you're using site_id property but there is no data property assigned to the first column with columns.data option.

Consider creating an example on JSFiddle based on one of these examples to further demonstrate the problem.