PrimeNg Datatable: Bind a dynamic array of objects

Viewed 1141

I have an array of objects like:

"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"
}

]

I want this to bind to my primeng datatable. Going through the this documentation, the datable requires data like,

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

In my case this data can be dynamic meaning displayName may come instead of name. How do I bind this data into my datatable. Thanks in advance!

1 Answers
Related