你知道如何在Angular Material的mat-table中固定第一列并使用水平滚动吗?
如果你能帮忙,我将不胜感激。

发布于 2019-01-09 20:59:30
对于这个- sticky值,您应该使用mat-table接口。
<ng-container matColumnDef="name" sticky>
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>请签入官方文档:https://material.angular.io/components/table/examples示例名称:“有粘性列的表”
发布于 2018-08-17 06:50:25
向您的组件添加一个方法,我们将其命名为isSticky(column)。然后将[sticky]绑定到它。请参阅下面的完整工作示例链接。
HTML
<div class="app-table-wrapper">
<table mat-table [dataSource]="dataSource" id="app-table">
<ng-container *ngFor="let column of displayedColumns" matColumnDef={{column}} [sticky]="isSticky(column)">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element">{{element[column]}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>S
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
</div>TS
isSticky (column: string): boolean {
return column === 'col1' ? true : false;
}完整示例
发布于 2022-01-19 07:04:02
需要在mat-table ng-中使用粘滞容器
.example-container {
height: 600px;
width: 550px;
overflow: auto;
}
td.mat-column-star {
width: 20px;
padding-right: 8px;
}
th.mat-column-position,
td.mat-column-position {
padding-left: 8px;
}
.mat-table-sticky:first-child {
border-left: 1px solid #e0e0e0;
padding-left: 6px;
width: 5%;
} <div fxFlex.gt-sm="100" fxFlex.gt-xs="100" class="example-container responsive-table">
<table mat-table [dataSource]="dataSource" >
<ng-container matColumnDef="name" sticky>
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let element"> {{name}} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Description </th>
<td mat-cell *matCellDef="let element"> {{desc}} </td>
</ng-container>
</table>
</div>
https://stackoverflow.com/questions/51640523
复制相似问题