Angular Material 排序表 - 如何将标题文本右对齐?

标签 angular sorting header angular-material

我正在使用 Angular Material 表。

我可以将列对齐设置为右对齐。

HTML:

<table mat-table [dataSource]="dataSource">
...
  <ng-container matColumnDef="position">
    <th mat-header-cell *matHeaderCellDef> No. </th>
    ...

CSS:

.mat-column-position {
    text-align: right;
}

但是当我使用排序功能时,列标题不再右对齐:

<table mat-table [dataSource]="dataSource" matSort>
...
  <ng-container matColumnDef="position">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> No. </th>
    ...

我猜问题出在“排序”符号上。

有什么想法吗?

Live demo

最佳答案

没错,它来自排序符号。解决此问题的一种方法是使用 CSS 仅更改 direction该标题从右到左:

.mat-header-cell.mat-column-position {
    direction: rtl;
}

/* If you want the same default margin for the sort icon */
:host ::ng-deep .mat-header-cell.mat-column-symbol .mat-sort-header-arrow {
    margin-right: 6px;
    margin-left: 0px;
}

或者,您可以在标题单元格上将 arrowPosition 属性设置为 before 以获得相同的结果:

<th mat-header-cell *matHeaderCellDef mat-sort-header arrowPosition="before">No.</th>

关于Angular Material 排序表 - 如何将标题文本右对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58269868/

相关文章:

html - Angular - 无法连接 HTML 页面中的值

c# - Winforms ListView C# 中的 collection.Insert(0, newItem) 与 list.Add(newItem) + Sort 更快吗?

android - 如何在android中创建多个 ListView

php - 从 php 数组中删除重复项(不是 array_unique)

php - 帮助在不更改当前页面的情况下更改页面语言(PHP)

c# - WPF:如何自动生成行标题而不仅仅是列标题?

javascript - 无法使用动态键对项目数组进行排序

html - 类型错误 : "setting getter-only property "value"

android - 将工作 Web 应用程序塑造为 Android 原生 Ionic 应用程序时出现 CORS 问题

php - 根据一组关键字的出现对sql结果进行排序