简体   繁体   English

如何在对话框中仅使表格内容可滚动? - Angular 材料

[英]How to make only table content scrollable in a dialog? - Angular Material

I have an Angular Material Dialog which contains Material Table .我有一个包含材料表Angular 材料对话框 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请在此处查看示例

It can be easily achieved by using flex:使用 flex 可以轻松实现:

Add dialog.component.scss file to styleUrls of your component with the following rules:使用以下规则将dialog.component.scss文件添加到组件的 styleUrls 中:

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

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

Add sticky: true to your table header:添加sticky: true到你的表header:

*matHeaderRowDef="displayedColumns; sticky: true"

Forked Stackblitz 分叉的 Stackblitz

Here is the working example:这是工作示例:

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

Just add this style on your table max-height: 200px;overflow:auto;只需在您的表格上添加此样式max-height: 200px;overflow:auto; & create mat header row sticky like this: &创建垫子 header 像这样粘贴:

<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在angular材质对话框内容中使overflow-x可见 - How to make overflow-x visible in angular material dialog content 如何使角材料卡占用可用的垂直空间并使其内容可滚动 - how to make angular material card to take available vertical space and make it's content scrollable 大 Angular 材料弹出窗口应该使父内容可滚动 - Large Angular material popover should make the parent content scrollable Angular Material Dialog - 内容投影 - Angular Material Dialog - content projection 如何在 Angular 7 中调整 Angular Material Dialog 的大小? - How to make Angular Material Dialog re sizable in Angular 7? 如何制作角度材料DIALOG在我的项目中可共享? - how to make angular material DIALOG Shareable in my project? 如何使“角度材质对话框”组件位于其他组件之上 - How to make a Angular Material Dialog component stay on top of other components 如何使“角度材质”对话框保持其绝对位置 - How to make Angular Material dialog persists its absolute position 如何使用 angular 和 ionic 制作固定 header 的可滚动表格 - How to make a scrollable table with fixed header using angular and ionic Angular Material 对话框内容中的响应式 Iframe - Responsive Iframe within Angular Material dialog content
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM