简体   繁体   English

排序后的角材工作台载荷数据

[英]angular material table load data after sorting

I am using angular material table to display data. 我正在使用角度材质表来显示数据。 Currently, i want to load angular material table sorted from status. 目前,我想加载按状态排序的角材表。 I have 3 status - complete, pending & fail. 我有3个状态-完成,未决和失败。 I want fail record to show last and complete and pending records should display first. 我希望失败记录显示最后一条,而完整和未决记录应该首先显示。

I used below sorting function to do it, but its not working. 我使用下面的排序功能来做到这一点,但它不起作用。

  this.dataSource = new MatTableDataSource(results['InvoiceHeaders']);
  this.dataSource.sortingDataAccessor = (item, property) => {
    switch (property) {
      case 'status': return item.element.status;
      default: return item[property];

      //     default: return item[property];
    }
  };
  this.dataSource.sort = this.viewsort;

Can u help me to do these type of sample. 您能帮我做这类样品吗?

Thanks 谢谢

One solution could be to create a field 'statusWeight' and assign a sortable numeric value to the 'status' column, and then use the default material sorting on that arbitary column. 一种解决方案是创建一个字段“ statusWeight”,并为“ status”列分配一个可排序的数值,然后在该任意列上使用默认的物料排序。

  • complete to have value 1 完整,具有价值1
  • pending to have value 2 待定值2
  • fail to have value 3 没有价值3

relevant HTML : 相关的HTML

<table mat-table [dataSource]="dataSource" matSort matSortActive="statusWeight" matSortDirection='asc' class="mat-elevation-z8">
....
</table>

working stackblitz available here 可在此处使用工作堆叠闪电战

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM