I am working on a feature where a dropdown menu controls the expansion of rows in a table. Depending on the option selected from the dropdown, different levels of items need to be displayed in the table. For example, selecting level 1 will expand the first row, level 2 will expand up to the second level (dish items), and selecting "All" will expand all rows in the table.
<select [(ngModel)]="expandModel"
(ngModelChange)="getoptionedExpansion($event)">
<option value="lvl1">level 1 </option>
<option value="lvl2">level 2</option>
<option value="lvl3"> Level 3 </option>
<option value="lvl4">level 4 </option>
<option value="all">All</option>
</select>
Table :
<table style="width:100%">
<thead>
</thead>
<tbody>
<ng-container *ngFor="let data of users">
<tr (click)="data.hideThis= !data.hideThis" style="border-bottom: 1px solid #DDE3ED;">
<td class="mainTitleFont cursor-pointer" style="font-size:16px">
<span *ngIf="data.hideThis">
-
</span>
<span *ngIf="!data.hideThis">
+
</span>
{{data.itemName}}</td>
</tr>
<ng-container *ngFor="let item of data.subItemsList">
<tr (click)="item.hideThis= !item.hideThis" style="font-size:15px; background-color: #edf2ef"
[hidden]="!data.hideThis">
<td *ngIf="data.hideThis">
<span *ngIf="item.hideThis">
-
</span>
<span *ngIf="!item.hideThis">
+
</span>
{{item.subitemName}}
</td>
</tr>
<ng-container *ngFor="let prod of item.items">
<tr (click)="prod.hideThis= !prod.hideThis" style="font-size:14px; background-color: #f2f2f2"
[hidden]="!data.hideThis || !item.hideThis">
<td>
<span *ngIf="prod.hideThis">
-
</span>
<span *ngIf="!prod.hideThis">
+
</span>
{{prod.itemName}}
</td>
</tr>
<ng-container *ngFor="let stock of prod.stocksList">
<tr (click)="stock.hideThis= !stock.hideThis" style="font-size:13px; background:#f5f7f6;"
[hidden]="!data.hideThis || !item.hideThis || !prod.hideThis">
<td>
<span *ngIf="stock.hideThis">
-
</span>
<span *ngIf="!stock.hideThis">
+
</span>
{{stock.stockName}}
</td>
</tr>
<ng-container *ngFor="let prodItem of stock.itemItemsList">
<tr (click)="prodItem.hideThis= !prodItem.hideThis" style="font-size:12px"
[hidden]="!data.hideThis || !item.hideThis || !stock.hideThis || !prod.hideThis">
<td style="width:100%">
{{prodItem.itemName}} <br>
<div class="list-class">
<span>
<ul>
<li> Portion</li>
<li>{{prodItem.date}} </li>
</ul>
</span>
</div>
</td>
</tr>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
</ng-container>
</tbody>
</table>
Access the DEMO for more information.