This answer is for only using Angular, we can do the Table row expand and collapse option.
I have given StackBlitz
In the TS file, we have created a variable to store table data.
data = [
{
id: 1,
name: 'Abc',
email: 'abc@mail.com',
isExpand: false,
address: [
{
add1: 'Delhi',
add2: 'Bangalore',
}
]
},
{
id: 2,
name: 'Xyz',
email: 'xyz@mail.com',
isExpand: false,
address: [
{
add1: 'Mumbai',
add2: 'Pune',
}
]
},
{
id: 3,
name: 'ijk',
email: 'ijk@mail.com',
isExpand: false,
address: [
{
add1: 'Chennai',
add2: 'Bangalore',
}
]
},
{
id: 4,
name: 'def',
email: 'def@mail.com',
isExpand: false,
address: [
{
add1: 'Kolkata',
add2: 'Hyderabad',
}
]
}
]
In the HTML file, we have a table.
<table>
<thead>
<tr>
<th></th>
<th>SL</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let row of data">
<tr>
<td (click)="row.isExpand = !row.isExpand">
<span *ngIf="!row.isExpand">+</span>
<span *ngIf="row.isExpand">-</span>
</td>
<td>{{ row.id }}</td>
<td>{{ row.name }}</td>
<td>{{ row.email }}</td>
</tr>
<tr *ngIf="row.isExpand">
<td colspan="4">
<table>
<thead>
<th>Address1</th>
<th>Address2</th>
</thead>
<tbody>
<tr *ngFor="let row2 of row.address">
<td>{{ row2.add1 }}</td>
<td>{{ row2.add2 }}</td>
</tr>
</tbody>
</table>
</td>
</tr>
</ng-container>
</tbody>
</table>