Jesse W
Jesse W

Reputation: 91

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

I want to display tooltip only for brand column

Using versions PrimeNG 9.2.1 on Angular 9.1.3

Upvotes: 1

Views: 3186

Answers (2)

Muhammed Albarmavi
Muhammed Albarmavi

Reputation: 24424

you can update cols to include some pTooltip value.

component

 this.cols = [
    { field: 'year', header: 'Year' , tooltip: 'Year 📅'},
    { field: 'brand', header: 'Brand' },
    { field: 'color', header: 'Color' , tooltip: 'Color of 🧙‍♂️'}
  ];

template

<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

Upvotes: 0

Arun
Arun

Reputation: 508

Use primeNg tooltip docs

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

Instead of col.header after ? place actual tooltip value as required.

Upvotes: 2

Related Questions