leovo2708 / ngx-treeview

An Angular treeview component with checkbox
MIT License
363 stars 337 forks source link

checked value of child item can not be changed programatically #202

Open LinWang2 opened 5 years ago

LinWang2 commented 5 years ago

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;
        }
      });
}

image

ramya0311 commented 4 years ago

@LinWang2 were you able to solve this issue?

ramya0311 commented 4 years ago

@leovo2708 is there a fix for this?