primeng icon indicating copy to clipboard operation
primeng copied to clipboard

Adding Templates and styles to Column dynamically in data table

Open braino15 opened this issue 10 years ago • 3 comments

Business case: I have column collection which keeps on changing for users. and some of the columns have custom templates associated with.

While trying to define the datatable in html like

<p-dataTable [value]="rows" [(selection)]="selectedVehicles" expandableRows="true" [totalRecords]="totalRecords" [lazy]="true" (onLazyLoad)="loadDataLazy($event)" (onRowSelect)="onRowSelect($event)" (onRowUnselect)="onRowUnselect($event)" [rows]="100" [paginator]="true" [pageLinks]="3" [rowsPerPageOptions]="[100,200, 500]" scrollable="true" scrollHeight="300px" [responsive]="true">

<p-column *ngFor="let col of columnDefs" [field]="col.fieldName" [header]="col.key" [filter] = "true"> <template *ngIf="col.hasTemplate" let-col let-row="rowData">

{{row[col.field]}}

it doesn't work. hasTemplate is boolean property on the columnDefs collection which has structure like [ {key: "interior color", fieldName: "intColor.colorDisplayName", style: " ", hasTemplate: false, template:""}, {key: "vin", fieldName: "vin", style: "", hasTemplate: true, template:"

{{row.entity.vin}}
"}].

The data table loads blank without any errors, with or without "template" property being used.

  1. How to add templates dynamically based on model property?
  2. how to set style with attributes like min-width and other classes, dynamically like form model.className property?

Any help?

Thanks.

braino15 avatar Aug 30 '16 18:08 braino15

+1

Nattujessy avatar Mar 23 '17 14:03 Nattujessy

Please use forum for "how-to" like cases.

cagataycivici avatar May 29 '17 13:05 cagataycivici

+1

iamkarthikrana avatar Jan 09 '18 09:01 iamkarthikrana