如何将工具提示添加到 primeNG table 中的特定 header 列

How to add tooltip to specific header column in primeNG table

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' }
        ];}}

我只想为品牌栏显示工具提示

在 Angular9.1.3

上使用版本 PrimeNG 9.2.1

使用 primeNg 工具提示 docs

<th *ngFor="let col of columns" [pTooltip]="col.field === 'brand' ? col.header : null"> {{col.header}} </th>

而不是 col.header? 之后根据需要放置实际的工具提示值。

您可以更新列以包含一些 p 工具提示值。

分量

 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>

stackblitz demo