首页 > 解决方案 > PrimeNG 使用数组对象排序

问题描述

我想知道是否可以使用对象数组将某些内容排序到表中?

我正在使用 Angular 11 和 PrimeNG 11.0.0-rc.1

this.cols = [        
    { field: 'day', header: 'Jour' },
    { field: 'class', header: 'Classe', type: "object", subField: 'classId'}
];

<ng-template pTemplate="header" let-columns>
    <tr>
       <th *ngFor="let col of columns" [pSortableColumn]="col.hasOwnProperty('subField') ? col.subField :  col.field">
            {{col.header}} 
            <p-sortIcon [field]="col.hasOwnProperty('subField') ? col.subField :  col.field"></p-sortIcon>
       </th>
       <th *ngIf="!isStudent && !isTeacher" style="width:5rem"></th>
    </tr>
    <tr>
       <th *ngFor="let col of columns">
           <p-columnFilter type="text" [field]="col.hasOwnProperty('subField') ? col.subField :  col.field" display="menu"></p-columnFilter>
       </th>
       <th *ngIf="!isStudent && !isTeacher"></th>
    </tr>
</ng-template>

我尝试使用上面的代码,但它不起作用

标签: angulartypescriptprimeng

解决方案


推荐阅读