angular - 带有分页和行跨度的材料表不起作用
问题描述
我在使用行跨度对材料表进行分页时遇到问题。rowspan 属性绑定本身就可以正常工作。但是当我引入分页时,它会导致值的重复。例如 id=5 的数据
{ id: 5, name: 'Boron', weight: 10.811, descriptions: ['row1'] },
输出看起来像
有什么办法可以避免这种情况吗?
请在此处找到 stackblitz 链接https://stackblitz.com/edit/angular-wudscb-9us1us?file=app%2Fapp.component.html
解决方案
您可以使用 mat-paginator 作为组件(不添加else 使用mat-paginatorthis.dataSource.paginator = this.paginator;
的事件和属性
但我建议你真的“按原样”显示表格。唯一的是“格式化”最后一个单元格
<ng-container matColumnDef="descriptions">
<th mat-header-cell *matHeaderCellDef>Descriptions</th>
<td mat-cell class="description-cell" *matCellDef="let data" >
<div class="inner-cell" *ngFor="let desc of data.descriptions;let last=last"
[class.no-border]="last" >
{{ desc }}
</div>
</td>
</ng-container>
并调整 .css
td.mat-cell.description-cell{
padding:0!important
}
.inner-cell{
padding-top: 14px !important;
padding-left: 16px !important;
padding-bottom: 14px !important;
border-bottom:1px solid rgba(0,0,0,.12);
}
.no-border{
border-bottom:none
}
你可以在这个 stackblitz中看到。看到它是直接使用的 dataSource = new MatTableDataSource<PeriodicElement>(ELEMENT_DATA);
(你不需要转换你的数据
推荐阅读
- javascript - Google Places 自动完成建议在 Angular 应用程序中的错误位置呈现
- primefaces - 如何防止 p:columnToggler 显示滚动条?
- java - 为每个客户端维护与 jersey CLIENT 的 cookie 会话
- javascript - 从严格导出默认模块内的另一个本地方法中调用本地 fooBar 方法时获取“_this.fooBar 不是函数”
- vba - 如何编写 VBA 代码以转到文件路径,打开文件夹然后打开文件?
- php - 在 Laravel 中,数据的布局/模板
- r - 如何从外部软件调用 CPLEX 的目标函数?
- clojure - binding form predefined outside let expression
- django - Django 中 urls.py 中 app_name 的用途是什么?
- javascript - 隐藏父菜单并显示子菜单