ngx-treeview
ngx-treeview copied to clipboard
checked value of child item can not be changed programatically
I have a ngx-treeview with decoupleChildFromParent is true, and I want to change checked and disabled attribute of child nodes programatically when I select or un-select parent node. if parent node is selected, child nodes are also changed to be seleced and disabled. if parent node is not selected, child nodes are changed to be usable only. it is so strange that disabled attribute can be changed as expected, but checked value is not ever changed. could you help me about it?
html
<ngx-treeview [config]="config" [items]="items" [itemTemplate]="itemTemplate"></ngx-treeview>
<ng-template #itemTemplate let-item="item" let-onCollapseExpand="onCollapseExpand">
<div class="form-inline row-item">
<i *ngIf="item.children" (click)="onCollapseExpand()" aria-hidden="true" class="fa" [class.fa-caret-right]="item.collapsed"
[class.fa-caret-down]="!item.collapsed"></i>
<div class="form-check">
<input type="checkbox" class="form-check-input" [(ngModel)]="item.checked" (ngModelChange)="onCheckboxChanged(item)" [disabled]="item.disabled"
/>
<label class="form-check-label" >
{{item.text}}
</label>
</div>
</div>
</ng-template>
ts
onCheckboxChanged(item: TreeviewItem) {
item.children.forEach(yearItem => {
yearItem.disabled = item.checked;
if (item.checked) {
yearItem.checked = item.checked;
}
});
}
@LinWang2 were you able to solve this issue?
@leovo2708 is there a fix for this?