如果需要使用p-tabel,请先intsll primeNg
https://mp.csdn.net/mdeditor/90108307#
Html:
动态获取数据
<p-table [columns]="cols" [value]="users" [reorderableColumns]="true" [resizableColumns]="true">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" pReorderableColumn pResizableColumn>
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-user let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{user[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
ts.
users: User[];
cols: any[];
ngOnInit() {
this.users = [
{ id: '1', name: 'kiran',email:'kiran@gmail.com' },
{ id: '2', name: 'tom',email:'tom@gmail.com' },
{ id: '3', name: 'john',email:'john@gmail.com' },
{ id: '4', name: 'Frank',email:'frank@gmail.com' },
];
this.cols = [
{ field: 'id', header: 'Id' },
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
];
}
export interface User {
id;
name;
email;
}