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

2
  • Same question has answered here: stackoverflow.com/questions/51709280/… Commented 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. Commented Jul 29, 2020 at 12:35

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @yurzui .. But it's problem if there are elements before the table which I don't want to scroll.
Please check the sample in the question again. Thanks for checking.
I updated my demo stackblitz.com/edit/…
Wish I could upvote your answer more than once. Thanks again.
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.