【问题标题】:Angular Material how set mat-sort-header from mat-tableAngular Material如何从mat-table设置mat-sort-header
【发布时间】:2018-05-17 21:02:33
【问题描述】:

我有角材料的下一张桌子:

<mat-table *ngIf="!waiting" class="table-general table-summary"  #table [dataSource]="dataSource" matSort>
    <mat-header-row class="header_row" *matHeaderRowDef="headerKeys"></mat-header-row>
    <mat-row class="row" *matRowDef="let row; columns: headerKeys;"></mat-row>
    <ng-container *ngFor="let key of headerKeys; let i = index">
      <ng-container matColumnDef="{{key}}">
        <mat-header-cell class="header_name header_{{key}}" *matHeaderCellDef mat-sort-header> {{getHeaderName(key)}} </mat-header-cell>
        <mat-cell class="cell cell_{{key}}" *matCellDef="let row">
          <div class="box_cell {{key}}">
            <div class="current_value ellipsis" *ngIf="key=='customer'">{{cellValue(row[key])}}</div>
            <mh-box-score
              *ngIf="key!='customer'"
              [value]="cellValue(row[key])"
              [type]="cellValue(row[key],'type')+' small'"
              [type_number]="'percent'"
              [previous_value]="cellValue(row[key],'diff')"
              [previous]="cellValue(row[key],'previousLabel')"
            ></mh-box-score>
          </div>
        </mat-cell>
      </ng-container>
    </ng-container>
  </mat-table>

它的工作完美。现在我想修改标题中排序箭头的位置,从according to the documentation之后到之前

我已经搜索了所有方法,但我无法做一些看起来如此简单的事情。

请帮忙,我在角度方面比较新

【问题讨论】:

    标签: angular typescript angular-material2


    【解决方案1】:

    为了移动箭头,您需要将@Input() 项目指令arrowPosition 应用于具有mat-sort-header 的DOM 元素:&lt;th mat-sort-header="name" arrowPosition='before'&gt;Dessert (100g)&lt;/th&gt;

    Here is a stackblitz example 了解如何将 arrowPosition 应用于直接从 Material 示例派生的各种表头。

    【讨论】:

    • 类型“字符串”不可分配给类型“MenuPositionX”
    • @GerardoBuenrostroGonzález 工作堆栈闪电战,这里是文件:material.angular.io/components/sort/api 显示相同的格式(并且输入是一个字符串。答案是正确的,所以你的错误可能来自不正确进口或其他来源。
    猜你喜欢
    • 2020-06-19
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多