0

I have an Angular Material Dialog which contains Material Table. I would like to make the table content scrollable (not even the table header). By default, the dialog's content is scrollable which is not what I want. Please see the example here

Akash
  • 4,412
  • 4
  • 30
  • 48
  • Same question has answered here: https://stackoverflow.com/questions/51709280/angular-6-material-data-table-with-fixed-header-and-paginator – Yogendra Chauhan Jul 29 '20 at 12:34
  • @YogendraChauhan I could make the content scrollable but it's a problem when I have the table in a dialog. – Akash Jul 29 '20 at 12:35

2 Answers2

2

It can be easily achieved by using flex:

Add dialog.component.scss file to styleUrls of your component with the following rules:

:host,
form  {
  display: flex;
  flex-direction: column;
  height: 100%;
}

form,
.table-body {
  flex: auto;
  overflow-y: auto;
}

Add sticky: true to your table header:

*matHeaderRowDef="displayedColumns; sticky: true"

Forked Stackblitz

yurzui
  • 205,937
  • 32
  • 433
  • 399
0

Here is the working example:

https://stackblitz.com/edit/angular-material-table-with-form-xuayxj

Just add this style on your table max-height: 200px;overflow:auto; & create mat header row sticky like this:

<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
Yogendra Chauhan
  • 805
  • 5
  • 15