I'm using Tree with checkboxes, and I want to add a button to check all checkboxes, I tried different methods but no good, the best thing i was able to achieve is this:
selectAllFiscal() {
this.rootItems.forEach(node => {
this.todoItemSelectionToggle(node);
});
}
rootItems is an array of root nodes.
I can see that nodes are selected when I iterate checklistSelection.selected
, but the checkboxes are not selected in the browser, can anybody point the problem, thanks.
Try the following for your method
checkAll(){
for (let i = 0; i < this.treeControl.dataNodes.length; i++) {
if(!this.checklistSelection.isSelected(this.treeControl.dataNodes[i]))
this.checklistSelection.toggle(this.treeControl.dataNodes[i]);
this.treeControl.expand(this.treeControl.dataNodes[i])
}
}
Stackblitz
https://stackblitz.com/edit/angular-hpsj5x?embed=1&file=app/tree-checklist-example.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With