How to Select All up to max limit using Gyrocode checkboxes plugin

How to Select All up to max limit using Gyrocode checkboxes plugin

TrevorWatTrevorWat Posts: 6Questions: 3Answers: 0

Hello!

I am using the Gyrocode checkboxes plugin, and I've run into a situation where I am trying to have a maximum number of selected rows and the select All checkbox does not trigger the function I put in place.
I'm using a server-side data source.

Here is what I added (trying to include just the relevant part, let me know if I should include more):

        table.on('select', function (e, dt, type, ix) {
            var selected = dt.column(0).checkboxes.selected();
            if (selected.count() > 5) {
                dt.rows(ix).deselect();
                alert("A maximum of 50 records can be added to a single document.");
            }
        });

The above works great when manually checking the boxes (it prevents the user from selecting more than 5). When checking the Select All box, though, it selects all of the items on the page (10), so obviously it's not triggering the above function.

I'm sure this is just a matter of adding something similar to that .on() method, but I'm not sure what. I checked [here] but I don't have an intuition for how to use these options.

Thank you!

(https://www.gyrocode.com/projects/jquery-datatables-checkboxes/reference/options/#columns.checkboxes.selectAllCallback "here ")

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm not sure how @gyrocode sets the checkboxes - I've pinged him here so hopefully he'll reply,

    Colin

  • TrevorWatTrevorWat Posts: 6Questions: 3Answers: 0

    Welp,

    I gotta get this thing done.

    I looked in the plugin (my first time digging in to plug-in code, woohoo) and was able to decipher some stuff (like the onClickSelectAll function), but ultimately it looks like adding some kind of a parameter for a max number is the good solution.

    While I was doing this it occurred to me I can just check the number of selected rows before submitting and tell the user to change it if it's above the max. That should work in this case, haha.

    Thank you!!

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    You can try contacting the developer directly. Not sure which will work better but you can try the Discuss button or maybe better the Report a Bug button to open an Issue in the github repo.
    https://www.gyrocode.com/projects/jquery-datatables-checkboxes/

    Kevin

Sign In or Register to comment.