Primeng 4.3:数据表列值“ S”,“ N”到“是”,“否”

时间:2019-08-29 12:39:53

标签: angular typescript primeng primeng-datatable

我有这些cols:

this.cols = [
   { field: 'acronym', header: 'Acrònim', sortable: true },
   { field: 'name', header: 'Nom', sortable: true },
   { field: 'commonUserName', header: 'Credencial', sortable: true },
   { field: 'scope', header: 'Àmbit', sortable: true },
   { field: 'transversal', header: 'Transversal', sortable: true },
   { field: 'startDate', header: 'Data Inici', sortable: true },
   { field: 'suspendDate', header: 'Data Suspensió', sortable: true },
];

HTML p-dataTable是:

<div style="margin-bottom: 1.54em" *ngIf="!apps.error">
    <p-dataTable #appsTable [value]="apps.content"...>
        <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [sortable]="col.sortable">
        </p-column>
    </p-dataTable>
</div>

表格如下:

enter image description here

如您所见,值是S|N,当值是"Yes"时我要显示"S",而当值是"No"时要显示"N"

数据是一个数组:

export interface ApplicationUser {
    acronym: string;
    code: string;
    commonUserName: string;
    description: string;
    name: string;
    transversal: string;
}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

使用模板列定义列

<p-column *ngFor="let col of cols" field="col.field" header="col.header">
    <ng-template let-col let-data="rowData" let-ri="rowIndex" pTemplate="body">
        <span>{{col.field=='transversal'?data[col.field]=='S'?'Yes':'No':data[col.field]}}</span>
    </ng-template>
</p-column>