I have list of array with parent and child level (parent level - child level - child level 1).
When I select any of the child level I am able to get selected parent level check box. When i deselect all child level parent level check box is not getting un-selected.
Here is the code used to find check box in html page
<div class="table rts-table-parentChild" *ngFor="let userRole of userRoleActions; let i = index">
<div class="table-cell">
<input type="checkbox" [ngModelOptions]="{standalone: true}" class="setup-checkbox" id="ChekCreate"
(ngModel)]="userRole.isCreateChecked" (change)="selectParentRole(i,'create')">
</div>
<div style="display:table-row-group;" *ngFor="let item of userRole.userRoleSubActions; let j = index">
<div class="table-cell">
<input type="checkbox" [ngModelOptions]="{standalone: true}"
class="setup-checkbox" [(ngModel)]="item.isCreateChecked"
(change)="isCreateChecked(i,'create')">
</div>
<div style="clear:both !important;" class="table-row" *ngFor="let
subitem of item.userRoleSubActions;let k=index">
<div class="table-cell">
<input type="checkbox" [ngModelOptions]="{standalone: true}"
class="setup-checkbox" [(ngModel)]="subitem.isCreateChecked"
(change)="isCreateChecked(i,'create')">
</div>
</div>
</div>
</div>
Above is the code for html file generation with parent and child relationship below is the code for select all function from parent and child checkbox selection
selectParentRole(currentIndex, roleType) {
for (var i = 0; i < this.userRoleActions[currentIndex].userRoleSubActions.length; i++) {
if (roleType === 'create') {
this.userRoleActions[currentIndex].userRoleSubActions[i].isCreateChecked = this.userRoleActions[currentIndex].isCreateChecked;
}
for (var j = 0; j < this.userRoleActions[currentIndex].userRoleSubActions[i].userRoleSubActions.length; j++) {
if (roleType === 'create') {
this.userRoleActions[currentIndex].userRoleSubActions[i].userRoleSubActions[j].isCreateChecked = this.userRoleActions[currentIndex].isCreateChecked;
}
}
}
}
isCreateChecked(index, roleType) {
for (var j = 0; j < this.userRoleActions[index].userRoleSubActions.length; j++) {
if (this.userRoleActions[index].userRoleSubActions[j].isCreateChecked && roleType === "create") {
this.userRoleActions[index].isCreateChecked = true; // console.log("isCreateChecked");
break;
}
for (var k = 0; k this.userRoleActions[index].userRoleSubActions[j].userRoleSubActions.length; k++) {
if (this.userRoleActions[index].userRoleSubActions[j].userRoleSubActions[k].isCreateChecked && roleType === "create") {
this.userRoleActions[index].isCreateChecked = true;
this.userRoleActions[index].userRoleSubActions[j].isCreateChecked = true;
break;
}
}
}
}
I want to un-select the parent checkbox while selecting the child checkbox
Aucun commentaire:
Enregistrer un commentaire