Add check in a checkbox once selectAll is clicked

Add check in a checkbox once selectAll is clicked

adrdgradrdgr Posts: 9Questions: 6Answers: 0

Hi all,

Here is a working example (it is not looking so good, but locally it looks good). It depicts a dropdown menu with with two options: 'All' and 'None'. Once 'All' is clicked, all table rows are selected. Here comes my question:
Is there a way to insert a check in checkbox once 'All' is clicked and remove this check once 'None' is clicked?

Any idea would be very helpful! Thank you

Answers

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin

    Listen for select and deselect and update the button's checkbox based on a check to see if all rows are selected or not.

    table.rows({selected: true}).count() === table.rows().count()
    

    would tell you if all rows are selected.

    Allan

  • adrdgradrdgr Posts: 9Questions: 6Answers: 0
    edited April 2022

    Thank you allan.

    I used the condition that you suggested above and $("input:checkbox").prop("checked", true); in order to add a check in the checkbox next to the dropdown arrow (my initial example was here).

    But, once I deselected a cell from the selected range of table rows, the count of the selected rows was not updated automatically and so the check in the checkbox was remained. It is wrong. In other words, I would like to update the 'status' of the checkbox next to the dropdown arrow based on the selected rows at each time. Is there a way to do that?

    Thank you

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

    @adrdgr Thanks for the test case, but I'm not seeing the problem you described - the counts are updating as expected. Please can you provide steps on how to reproduce,

    Colin

Sign In or Register to comment.