I have a list of person which I want to display in a primeng datatable. The person object has this fields (firstName, lastName, continentsVisited). continentVisited field is an array of continent visited by the person. This continentsVisited is dynamic. What I want is to have a seperate column for each continent visited in addition to firstName and lastName.
export class AppComponent {
persons: any [] = [
{"firstName": "paolo","lastName":"revira","continentsVisited": [
{ "continent":"Europe", "name": "UK" },
{ "continent":"Asia", "name": "China" },
{ "continent":"North America", "name": "US" }
]},
{"firstName": "kenneth","lastName":"santos"},"continentsVisited": [
{ "continent":"Europe", "name": "France" },
{ "continent":"Asia", "name": "Japan" },
{ "continent":"North America", "name": "Canada" }
]},
{"firstName": "chris","lastName":"kenndy"},,"continentsVisited": [
{ "continent":"Europe", "name": "Germany" },
{ "continent":"Asia", "name": "Philippines" },
{ "continent":"North America", "name": "Mexico" }
]},
];
ngOnInit() {
}
}
<p-dataTable [value]="persons" [editable]="true" resizableColumns="true" reorderableColumns="true">
<p-column field="firstName" header="First Name" [editable]="true"></p-column>
<p-column field="lastName" header="Last Name"></p-column>
</p-dataTable>
I have created a plunkr for this. here's the link https://plnkr.co/edit/gS1wsI?p=preview
