Imagine you fetched data from your backend like that :
this.backendData = {
cols:['name', 'Income last year'],
rows:[['Lionbridge', 150250], ['Locatech', 1085]]
}
First, you have to create PrimeNG columns dynamically from these backend data :
this.cols = [];
var i, row, obj;
for(i=0;i<this.backendData.cols.length;i++) {
this.cols.push(this.constructColumn(this.backendData.cols[i]));
}
Then, you have to fill the data for the PrimeNG datatable like that (by iterating on each row of backend rows data) :
this.data = [];
for(row=0;row<this.backendData.rows.length;row++) {
obj = {};
for(i=0;i<this.backendData.cols.length;i++) {
obj[this.backendData.cols[i]] = this.backendData.rows[row][i];
}
this.data.push(obj);
}
Finally, just associate that data to the view :
<p-dataTable [value]="data">
<p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header"></p-column>
</p-dataTable>
Here is a working Plunker
Is that ok for you ?