【问题标题】:matSort on dynamic mat-table angularmatSort 动态垫表角度
【发布时间】:2020-11-21 18:02:16
【问题描述】:

我正在尝试对动态垫表中的标题进行排序,但它似乎没有做任何事情。我觉得我什么都试过了。 HTML

<table fxFlex mat-table matSort [dataSource]="dataSource">
  <ng-container *ngFor="let column of columns">
    <ng-container [matColumnDef]="column.jsonPath">
      <th mat-header-cell mat-sort-header *matHeaderCellDef>{{column.label}}</th>
      <td mat-cell *matCellDef="let obj">
        {{getValueByJsonPath(obj: any}}
      </td>
    </ng-container>
  </ng-container>
</table>

TS

dataSource = new MatTableDataSource<any>([]);

...

  ngAfterViewInit() {
    this.dataSource.paginator = this.paginator;
    this.dataSource.sort = this.sort;
  }

但是 matSortActive 似乎强制执行某些操作,但在第二次点击时什么也不做。

  <table fxFlex mat-table matSort matSortActive="name" matSortDirection="asc"[dataSource]="dataSource">

【问题讨论】:

    标签: angular mat-table


    【解决方案1】:

    刚刚遇到类似的问题。我忘了导入MatSortModule

    import {MatSortModule} from '@angular/material/sort';
    

    这样做后,我得到了排序箭头。

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 2021-10-07
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-05-03
      相关资源
      最近更新 更多