export class TableSectionsDemo implements OnInit {
cars: Car[];
cols: any[];
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsSmall().then(cars => this.cars = cars);
this.cols = [
{ field: 'vin', header: 'Vin' },
{ field: 'year', header: 'Year' },
{ field: 'brand', header: 'Brand' },
{ field: 'color', header: 'Color' }
];
}
}
<p-table [columns]="cols" [value]="cars">
<ng-template pTemplate="caption">
List of Cars
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
<ng-template pTemplate="footer" let-columns>
<tr>
<td *ngFor="let col of columns">
{{col.header}}
</td>
</tr>
</ng-template>
<ng-template pTemplate="summary">
There are {{cars?.length}} cars
</ng-template>
</p-table>