jeudi 2 février 2017

Angular 2 select/deselect all checkbox

I have a question. Lets say I have structure of company with different divisions and people assigned to those divisions in TypeScript. I want to export them, but only when checkbox in export is set. Export screen allow to check people that I want to export and allows to select all division or even whole company. Modification after selecting/deselecting company/division checkbox is easy, I found some ideas and I have some by my own.
Angular 2 checkbox check all
Angular2 How to get all selected check boxes.
The problem is make checkboxes professional and managing divisions/company checkboxes if all children checkboxes are selected. In case the is 50 000 employees it may be hard to do. I have 2 ideas:

  1. Give each checkbox on change event that will check state of other checkboxes in division/company and will save result in boolean for each division/whole company and bind to it with angular to see if I needs to check/unchecked select all checkbox for division/company. The problem is iterating over employees with 50k of them in company after each change...
  2. Make structure that is holding ID of selected people and guards length of that set - each time I add new person it increases size and decreases with deselect. That way I can with lighting fast speed asses after each change if all people are selected in division/company by comparing employees count for division with selected count. Maybe even TypeScript/Angular2 have some kind of structure that is optimised for length property read. The only problem is initialization - it may be time consuming...

Those are my ideas. If someone knows Angular better and knows better solution I will be grateful.

Aucun commentaire:

Enregistrer un commentaire