【问题标题】:matSort headers not sorting table at allmatSort 标题根本没有排序表
【发布时间】:2018-11-02 12:56:59
【问题描述】:

我很难让可排序的标题正常工作。我附上了我的应用程序的现场演示,其中标题排序不起作用,以及我用来实现它的代码。当我单击标题时,我没有得到响应。没有错误,没有排序,没有反馈。我做了以下事情:

  1. 向表中添加了matSort 指令。
  2. 为每个标题添加了mat-sort-header
  3. 已将MatSortModule 导入app.module.ts
  4. 为表数据源提供了MatSort 指令。

标题是可点击的,它们有切换箭头,但点击时行没有被排序。

【问题讨论】:

    标签: angular-material


    【解决方案1】:

    这是因为您在表格在 DOM 中呈现之前将数据源的排序初始化为 matSort(因为 *ngIf)

    this.notes.sort = this.sort;
    

    改变这一行

    <table mat-table [dataSource]="notes" *ngIf="notes.data" matSort>
    

    <table mat-table [dataSource]="notes" [hidden]="!notes.data" matSort>
    

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 2012-01-19
      • 2012-10-28
      • 2019-08-28
      • 2019-07-26
      • 2019-01-26
      • 2017-05-14
      • 2019-10-05
      • 1970-01-01
      相关资源
      最近更新 更多