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

selectAll callback issue #126

Closed nonoantog closed 3 years ago

nonoantog commented 3 years ago

HI,

I want to do some stuff when the user selects the checkbox in the header.

But, every time I check a row in the table body, it is calling to selectCallBack and it is calling selectAllCallback callback.

So.. is there a way to identify that the callback is from the header and not from the body row?

1) select a row in the body => callbacks called, select,selectAll 2) select from header check => callbacks called, selectAll

I know this is a question, not an issue. It should be tagged as questions.

Thanks.

vonDassendorf commented 3 years ago

The extension injects three parameter to the callback, nodes, selected and indeterminated. I use an if statement to check if the selectAll checkbox is in indeterminated state or not like this:

function toggleAllAccess(nodes, selected, indeterminated) {
    if (selected && !indeterminated) {
        console.log(nodes);
    }
}
mpryvkin commented 3 years ago

There is selectAllCallback option that allows you to define a function which will be called when "Select all" control in the header is clicked. Please see sample function provided by @vonDassendorf .

Jequex commented 1 year ago

Clicking the checkbox on a row calls both functions => selectCallback and selectAllCallback likewise clicking on the select all checkbox. Is there a way around this?