Search code examples
angularhyperlinkanchorprimengprimeng-datatable

How to add hyperlink to Primeng datatable column,angular 2 way


I am using Primeng datatable in my project setup.But i want the first column of all rows to be hyperlink,so that i can link those to the next pages using [routerLink] (angular 2 way).I am quite unable to achieve that...

Is there any way to work around this one in primeng..?

Thanks in advance!


Solution

  • I am your real maseeaha try this it is working:

    <p-dataTable [value]="cars">
        <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header">
            <template let-row="rowData" pTemplate>
                  <span *ngIf="col.header==='Vin'"><a style="color:blue;" routerLink="/prbDetails/{{row.vin}}">{{row[col.field]}}</a></span>
                  <span *ngIf="col.header!=='Vin'">{{row[col.field]}}</span>
            </template>
        </p-column>
    </p-dataTable>