angular - 无法更改 Angular mat-table 列顺序
问题描述
mat-table
我在此页面上使用 Material 创建了一个基本列表,并且它可以正常工作。但是,当尝试将操作列移动到下表 a 的末尾列时,第一列的顺序保持不变,这没有任何意义。
<!-- I move this just below the tr tags -->
<!-- action column -->
<ng-container *ngIf="rowActionIcon?.length" [matColumnDef]="rowActionIcon">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element" [id]="rowActionIcon" (click)="emitRowAction(element)">
<button mat-button>
<mat-icon>remove_shopping_cart</mat-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
我还想在 Actions 列中创建 3 个图标作为表格的最后一列。任何想法来解决这个问题?
解决方案
我没有使用 mat-table,但在这里快速浏览一下会告诉我顺序取决于行的定义。
<!--- Note that these columns can be defined in any order.
The actual rendered columns are set as a property on the row definition" -->
我认为您需要将table.component.ts中的顺序更改
为this.displayedColumns = [...columnNames, this.rowActionIcon]
推荐阅读
- swift - Swift 中的打印机秤
- r - 如何在重新启动 R Shiny 应用程序或查询时保存已编辑的数据框并将其加载回来?
- kubernetes - 将networking.k8s.io/v1beta1移植到v1
- angular - 带数字的楼梯图案(角度)
- vuejs2 - VUEJS npm run dev:模块解析失败:意外令牌
- reactjs - 如何在 React 中正确显示某些变量
- tensorflow - Seq2Seq 模型为所有句子返回相同的向量
- c++ - C 或 C++ websocket 客户端工作示例
- reactjs - 如何平滑地重新渲染昂贵的组件
- c# - C# 通过 REST 接受 null 或字符串