为什么垫子分类不能在垫子桌上工作

时间:2019-10-27 13:50:10

标签: angular-material-7

我在一页上使用了多个席子表。我需要一张桌子垫子。

当我调试代码响应时会得到结果,但matSort无法正常工作

 <table #transactions class="transactions-table" mat-table [dataSource]="trassactionDataSource" matSort>
     <ng-container matColumnDef="id">
         <th mat-header-cell *matHeaderCellDef mat-sort-header> Transaction ID </th>
         <td mat-cell *matCellDef="let row"> {{row.transaction_id}} </td>
     </ng-container>

     <ng-container matColumnDef="product_name">
         <th mat-header-cell *matHeaderCellDef mat-sort-header> Product </th>
         <td mat-cell *matCellDef="let row"> {{row.listing_title}} </td>
     </ng-container>

.....

     <tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
     <tr mat-row *matRowDef="let row; columns: displayedColumns;">         </tr>
</table>

'

displayedColumns: string[] = ['id', 'product_name', ...];

@ViewChild(MatSort)private sort: MatSort;

 ngOnInit() {
       this.userService.getDashboardData().subscribe((response) => {
      if (response.code == 401) {
        this.authService.logout(true);
      } else {

           this.trassactionDataSource = new MatTableDataSource(response.result.transactions);

           var that = this;
           setTimeout(function () {
               that.trassactionDataSource.sort = that.sort;
           }, 500);
      }
}[enter image description here][1]

我没有任何控制台错误。

1 个答案:

答案 0 :(得分:0)

感谢您阅读本文。我知道了。 matColumnDef = response result

例如:

 <ng-container matColumnDef="id">
         <th mat-header-cell *matHeaderCellDef mat-sort-header> Transaction ID </th>
         <td mat-cell *matCellDef="let row"> {{row.transaction_id}} </td>
     </ng-container>

更改为

 <ng-container matColumnDef="transaction_id">
         <th mat-header-cell *matHeaderCellDef mat-sort-header> Transaction ID </th>
         <td mat-cell *matCellDef="let row"> {{row.transaction_id}} </td>
     </ng-container>