2017-07-21 35 views
1

的動態數組我有對象像數組:PrimeNg數據表:綁定對象

"rows": [ 
{ 
    "id": 1, 
    "createdAt": "2017-07-21T06:05:38.000Z", 
    "updatedAt": "2017-07-21T06:05:38.000Z", 
    "createdBy": null, 
    "modifiedBy": null, 
    "name": "ABC", 
    "owner": "Dian", 
    "age": 23, 
    "industry": "abc" 
}, 
{ 
    "id": 2, 
    "createdAt": "2017-07-21T06:05:38.000Z", 
    "updatedAt": "2017-07-21T06:05:38.000Z", 
    "createdBy": null, 
    "modifiedBy": null, 
    "name": "ABsC", 
    "owner": "Disdan", 
    "age": 23, 
    "industry": "absdc" 
} 

]

我想這將綁定到我的primeng數據表。通過這個documentation走出去,在確定時代需要像數據,

[ 
     {field: 'vin', header: 'Vin'}, 
     {field: 'year', header: 'Year'}, 
     {field: 'brand', header: 'Brand'}, 
     {field: 'color', header: 'Color'} 
    ]; 

在我的情況下,這個數據可以是動態的含義顯示名可能會代替。我如何將這些數據綁定到我的數據表中。提前致謝!

回答

0

其實很簡單。不要提供一個字段,添加一個ng-template並使用您需要的任何邏輯來確定在該字段中顯示的內容。

例如:

<p-column header="Whatever You Want Displayed In The Column Header"> 
    <ng-template let-entry="rowData" pTemplate="body"> 
     {{ (entry.id === 1 ? entry.displayName : entry.name) }} 
    </ng-template> 
</p-column>