html - 使用 ngStyle 为粘性列设置 Angular 材质数据表标题左侧 CSS 属性?
问题描述
在这个演示中,我试图将动态的left
CSS 属性设置为使用,但看起来 Angular 用它认为应该是的值覆盖了值......在应用更新后。CUSTOMER
mat-header-cell
64px
ngStyle
216px
ngStyle
https://stackblitz.com/edit/angular-material-data-table-module-styling-sticky-column-adjust
关于如何解决这个问题的想法?
解决方案
正如您所说,由于某些默认覆盖,它不会占用 64px。在这种情况下,我们需要使用 left:64px !important。但是使用 ngStyle 时不支持使用 '!important'。因此,我们在 css 文件中定义了一个新类
.leftMargin {
left: 64px !important;
}
并且在 ngFor 循环中,我们仅在列名为“客户”时应用此 css 类。
<ng-container *ngFor="let c of COLUMNS" matColumnDef="{{c.toUpperCase()}}" [sticky]="isSticky(c)">
<mat-header-cell [ngClass]="{'leftMargin': c=='CUSTOMER'}" [ngStyle]="styleHeaderCell(c)" *matHeaderCellDef mat-sort-header>
{{c.toUpperCase().split('_').join('')}}
</mat-header-cell>
<mat-cell *matCellDef="let row;">{{row[c.toLowerCase()] ? row[c.toLowerCase()] : row[c.toUpperCase()]}}
</mat-cell>
</ng-container>
请参阅此 stackblitz 列表:https ://stackblitz.com/edit/angular-material-data-table-module-styling-sticky-column-cywshb?file=src%2Fapp%2Fapp.component.html
推荐阅读
- vba - 确定一个单词是否在匹配的 125 个单词内
- azure - Azure - 机器人频道注册设置已更改,连接已删除
- hadoop - Hadoop ApplicationClassLoader 找不到类
- docker - 使用 ssh 从 git repo 中提取,使用 docker-compose 中的秘密
- python - 如何以 graphml 格式保存 MultiDigraph?
- sockets - 将 Socket 编程从 Ubuntu 移植到 Windows
- r - 如何在 R 中为 Shiny 应用程序输入变量文件?
- go - 继承语法。有什么区别?
- python - 如何在考虑 DST 的同时将 UTC HH:MM(无日期)转换为基于时区的本地时间?
- javascript - 如何在以下情况下正确使用 async-await?