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
-
Same question has answered here: stackoverflow.com/questions/51709280/…Yogendra Chauhan– Yogendra Chauhan2020-07-29 12:34:35 +00:00Commented Jul 29, 2020 at 12:34
-
1@YogendraChauhan I could make the content scrollable but it's a problem when I have the table in a dialog.Akash– Akash2020-07-29 12:35:47 +00:00Commented Jul 29, 2020 at 12:35
Add a comment
|
2 Answers
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"
4 Comments
Akash
Thanks @yurzui .. But it's problem if there are elements before the table which I don't want to scroll.
Akash
Please check the sample in the question again. Thanks for checking.
yurzui
I updated my demo stackblitz.com/edit/…
Akash
Wish I could upvote your answer more than once. Thanks again.
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>