Adding Templates and styles to Column dynamically in data table
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">
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:"
The data table loads blank without any errors, with or without "template" property being used.
- How to add templates dynamically based on model property?
- how to set style with attributes like min-width and other classes, dynamically like form model.className property?
Any help?
Thanks.
+1
Please use forum for "how-to" like cases.
+1