HTML
<p-table #dt1 [columns]="cols" [value]="cars1">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns"> {{col.header}} </th>
</tr>
</ng-template>
</p-table>
TS
export class Table implements OnInit {
cols: any[];
ngOnInit() {
this.cols = [
{ field: 'year', header: 'Year' },
{ field: 'brand', header: 'Brand' },
{ field: 'color', header: 'Color' }
];}}
我只想为品牌栏显示工具提示
在 Angular 9.1.3 上使用 PrimeNG 9.2.1 版本
答案 0 :(得分:1)
使用 primeNg 工具提示 docs
<th *ngFor="let col of columns" [pTooltip]="col.field === 'brand' ? col.header : null"> {{col.header}} </th>
根据需要放置实际的工具提示值,而不是 col.header
之后的 ?
。
答案 1 :(得分:0)
您可以更新 cols 以包含一些 pTooltip 值。
组件
this.cols = [
{ field: 'year', header: 'Year' , tooltip: 'Year ?'},
{ field: 'brand', header: 'Brand' },
{ field: 'color', header: 'Color' , tooltip: 'Color of ?♂️'}
];
模板
<p-table #dt1 [columns]="cols" [value]="cars1">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pTooltip]="col.tooltip"> {{col.header}} </th>
</tr>
</ng-template>