jeudi 7 février 2019

select-all feature on list of check-boxes

I have a list of items along with their associated check-boxes.

And I'd like to achieve the following:

  • select/un-select all items in list using "Select All" checkbox.
  • select/un-select individual items in list.
  • when all items are selected and any of the selected items is clicked, u-nselect "Select All" checkbox.

Most of these steps are working as expected, except, when I :

  • select all list-items by checking the "Select All" checkbox
  • un-checking any of the selected items
  • then again checking "Select All" checkbox.

This causes that any list-item I un-selected before clicking on "Select All" checkbox, remain un-selected.

enter image description here

It looks as if (for some reason) the internal state of the checkbox is not being changed in this case.

Although, when :

  • all list-items are un-selected and I select any of the list-items
  • then check the "Select All" checkbox

it correctly selects all list-items. So I'm a little confused as why it's not working in the other case mentioned above.

Note: The main reason , I don't want to store state for every item in the list, is that I will be using this in a table with virtual-scroll. Which fetches data page by page.. So I don't have access to all items data, hence, I only store either items I manually selected or un-selected.

StackBlitz link




Aucun commentaire:

Enregistrer un commentaire