首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >分类对象属性角材料

分类对象属性角材料
EN

Stack Overflow用户
提问于 2020-12-09 13:40:58
回答 1查看 362关注 0票数 0

我正试着用垫子排序头对一张垫子进行排序。我可以用字符串或数字这样的公共属性来完成这个任务。

代码语言:javascript
复制
 <table #tablaClientes mat-table [dataSource]="dataSource" matSort multiTemplateDataRows>
  <!-- Id Column -->
  <ng-container matColumnDef="idIngreso">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>Id Comprobante</th>
    <td mat-cell *matCellDef="let row">{{row.idIngreso}}</td>
  </ng-container>
  <!-- Proveedor Column -->
  <ng-container matColumnDef="idProveedor">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>Nombre Proveedor</th>
    <td mat-cell *matCellDef="let row">{{row.idProveedor.nombre}}</td>
  </ng-container>
  <!-- Fecha Compra Column -->
  <ng-container matColumnDef="fechaCompra">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>Fecha de Compra</th>
    <td mat-cell *matCellDef="let row">{{row.fechaCompra}}</td>
  </ng-container>
  <!-- Fecha Recepcion Column -->
  <ng-container matColumnDef="fechaRecepcion">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>Fecha de Recepcion</th>
    <td mat-cell *matCellDef="let row">{{row.fechaRecepcion}}</td>
  </ng-container>
  <!-- Monto Total Column -->
  <ng-container matColumnDef="totalIngreso">
    <th mat-header-cell *matHeaderCellDef mat-sort-header>Monto Total</th>
    <td mat-cell *matCellDef="let row">{{row.totalIngreso |currency}}</td>
  </ng-container>

但是,我不能按idProveedor进行排序,因为它是一个对象。

非常感谢!

EN

回答 1

Stack Overflow用户

发布于 2020-12-29 07:38:06

更简单的方法是在dataSource中添加一个新属性,并按照这个新属性(如这是如此 )进行排序(实际上,如果您不需要"idProveedor“对象,则可以将您的dataSource转换为

代码语言:javascript
复制
this.data.forEach(x=>{
   x.proveedorNombre=x.idProveedor.nombre
   delete x.idProveedor
}

另一个解决方案是创建一个sortingDataAccesor

代码语言:javascript
复制
this.dataSource.sortingDataAccessor = (item, property) => {
     if (property=="idProveedor")
         return item.nombre;
     if (property=="idIngreso")
        return item.idIngreso
     if (property=="fechaCompra")
        return item.fechaCompra

     ...
}

一个在这一堆闪电战中简单的例子

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65217956

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档