Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand and collapse table row in angular material

Below is the example where only expansion is happening, but I want the row to collapse when you click it.

https://stackblitz.com/edit/angular-material-expandable-table-rows?file=app%2Ftable%2Ftable.component.ts

I want my table to be like this:

table

Please help.

like image 417
Priyanka Avatar asked Jul 24 '18 08:07

Priyanka


1 Answers

Replace (click)="expandedElement = row"

with

(click)="expandedElement === row? expandedElement = null : expandedElement = row"

https://stackblitz.com/edit/angular-material-expandable-table-rows-8ypyfu?file=app%2Ftable%2Ftable.component.html

like image 85
Yousef khan Avatar answered Oct 22 '22 04:10

Yousef khan