Dynamic ng-template in p-table or p-dataTable

UI Components for Angular
Post Reply
Danieleee
Posts: 22
Joined: 17 Oct 2016, 11:14

16 Mar 2018, 12:45

In Dynamic columns I can do this:

Code: Select all

<p-dataTable [value]="cars"> <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header" [style]="col.style"></p-column> </p-dataTable>
How I can add dynamic(different) template for every columns like this?

Code: Select all

<ng-template pTemplate="filter" let-col> <p-calendar (onSelect)="setFiltri(col.value,col.field)" [(ngModel)]="dataStato" dateFormat="dd/mm/yy" [locale]="calendario" appendTo="body"></p-calendar> </ng-template>

dragon18
Posts: 14
Joined: 06 Sep 2017, 12:39

16 Mar 2018, 18:35

You can use *ngIf on template according with boolean attributes setted in each column. For example:

Code: Select all

<ng-template *ngIf="col.date" pTemplate="filter" let-col>
   <p-calendar>....</p-calendar>
</ng-template>
<ng-template *ngIf="col.flag" pTemplate="filter" let-col>
   <i>...</>
</ng-template>
I hope this can help you...

nybroe
Posts: 3
Joined: 23 May 2018, 08:44

16 Jul 2018, 22:59

Using the *ngIf on ng-template within p-table did not work for me.
I also tried using [ngIf] - still no result..

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 6 guests