Deselect all not working in this case.

Deselect all not working in this case.

itajackassitajackass Posts: 165Questions: 49Answers: 3

Hi i create a example where during a SELECT ALL operation in header, one row is not allowed to be selected, so i added a script to deselect the row based on a class.

Now if I reclick the select in the header to "deselect all", it does nothing...
here my fiddle: https://live.datatables.net/nulisonu/1/edit

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    It does nothing because it sees that not all rows are selected and thus tries to select the unselected rows. However, your event handler prevents that from happening, thus, nothing happens.

    The select all event handler has no knowledge of the fact that you want a specific row to be unselectable, so this isn't an unsurprising outcome.

    Modifications to the library would be needed to have some internal knowledge of what rows shouldn't be selectable to make this scenario work.

    Allan

  • itajackassitajackass Posts: 165Questions: 49Answers: 3

    ok, so i'll need to find a workaround:

    Is there a way to know if table.on('select') event is triggered from a row click or from the header "select-all" element?
    I see "type" parameter, but has not info what i want

    Maybe a table.on('selectAll') event could be usefull to determinate this scenario?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    selectAll might work, but you'd then need to override the default action (which the DataTables events don't normally allow), check if all the rows you want selectable are selected and then deselect them.

    I think it might be more straight forward to simply put your own checkbox into the header and bind an event listener that does what you need.

    Allan

Sign In or Register to comment.