Reputation: 798
I've got almost 1 to 1 tree from this example: https://stackblitz.com/angular/nnxeaxmrdob?file=src%2Fapp%2Ftree-checklist-example.ts
What i need is to get all the selected values and those which are indeterminate. I know, that all selected values are hold in checklistSelection variable, however the problem is when the whole child node is selected, and I've got array of parents and children, but while only some children are selected, then I don't have parents.
So once again, how do i get values that are selected AND indeterminate?
Upvotes: 2
Views: 4339
Reputation: 57971
In the example, you can use
const partial=this.treeControl.dataNodes
.filter(x=>this.descendantsPartiallySelected(x))
console.log(this.checklistSelection.selected,partial)
Where (*)
descendantsPartiallySelected(node: TodoItemFlatNode): boolean {
const descendants = this.treeControl.getDescendants(node);
const result = descendants.some(child => this.checklistSelection.isSelected(child));
return result && !this.descendantsAllSelected(node);
}
(*)You has yet this function in the example
Upvotes: 4