My Objective: To display an expandable dynamic table without using any external table-library.
What I did: Currently, I'm looping inside a <div> to display a table (It works!). Now, I also want to add a button in front of every table-row, which when clicked will display some additional information related to that particular row. For that purpose I'm using ng-bootstrap's Collapse.
Issue I'm facing: As every row is expandable and the number of row is dynamic, I'm unable to figure out how can I build an expandable table row without initializing some variable within .ts file first. Also, I want all the rows to be closed at the beginning. As of now, all the expansion button have same id and refer to same boolean variable. Hence, whenever I try to expand one row, every row gets expanded.
Here's my code in HTML:
<div style="display: table-row" *ngFor="let row of rows">
<button type="button" class="btn" (click)="'isCollapsed'+row.id = !'isCollapsed'+row.id" [attr.aria-expanded]="false"
aria-controls="'collapse'+row.id">
E
</button>
<div id="'collapse'+row.id" [ngbCollapse]="'isCollapsed'+row.id">
<div class="card">
<div class="card-body">
Some dynamic table content
</div>
</div>
</div>
<div style="display: table-cell;">
<input type="checkbox" [checked]="chk" [id]="row.id" [name]="row.id">
</div>
<div style="display: table-cell;"> {{row.id}} </div>
<div style="display: table-cell;"> {{row.name}} </div>
<div style="display: table-cell;"> {{row.address}} </div>
<div style="display: table-cell;"> {{row.package}} </div>
<div style="display: table-cell;"> {{row.notes}} </div>
<div style="display: table-cell;"> {{row.price}} </div>
<div style="display: table-cell;"> {{row.status}} </div>
</div>