PrimeNG TurboTable:dataKey 是否需要是一列?
PrimeNG TurboTable: Does dataKey need to be a column?
p-table 上的 dataKey 属性 是否需要定义为一列,还是只需要是 [value] 数组中对象的 属性 ?如果需要是一列,这个列是否需要可见?
不,dataKey不需要是列。
dataKey 应该是记录的 属性,但不需要显示以供 table 使用。
HTML:
<p-table [columns]="cols" [value]="cars" [(selection)]="selectedCars" dataKey="vin">
<ng-template pTemplate="header" let-columns>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.year}}</td>
</tr>
</ng-template>
</p-table>
打字稿:
export class TableDemo implements OnInit {
cars: Car[];
cols: any[];
constructor() { }
ngOnInit() {
this.cars = [
{ vin: '123ABC', year: 1994 },
{ vin: '234BCD', year: 1978 },
{ vin: '345CDE', year: 2015 },
];
this.cols = [
{ field: 'year', header: 'Year' }
];
}
}
p-table 上的 dataKey 属性 是否需要定义为一列,还是只需要是 [value] 数组中对象的 属性 ?如果需要是一列,这个列是否需要可见?
不,dataKey不需要是列。
dataKey 应该是记录的 属性,但不需要显示以供 table 使用。
HTML:
<p-table [columns]="cols" [value]="cars" [(selection)]="selectedCars" dataKey="vin">
<ng-template pTemplate="header" let-columns>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</ng-template>
<ng-template pTemplate="body" let-car>
<tr>
<td>{{car.year}}</td>
</tr>
</ng-template>
</p-table>
打字稿:
export class TableDemo implements OnInit {
cars: Car[];
cols: any[];
constructor() { }
ngOnInit() {
this.cars = [
{ vin: '123ABC', year: 1994 },
{ vin: '234BCD', year: 1978 },
{ vin: '345CDE', year: 2015 },
];
this.cols = [
{ field: 'year', header: 'Year' }
];
}
}