angular - PrimeNg p-datatable is not picking the provided template -
i have use case wherein have varying number of rows , columns table. not have information header names.
i trying use following implementation:
i fetch reference table using @viewchild('tableref ') tableref ; call service fetch columns list , assign as: tableref .columns = colarray;
this colarray contains objects having field , headers property automatically assigned table. (this working fine , can see header name in table)
i preparing array of objects data, objects have property name same field name picked colarray.
finally in html have:
<div class="col-sm-12 kill-padding table"> <p-datatable #tableref [value]="data" rowhover="true"> <p-column> <ng-template ptemplate="body" let-col let-row="rowdata"> <div [ptooltip]="row[col.field]" tooltipposition="bottom"> <h2>{{row[col.field]}}</h2> </div> </ng-template> </p-column> </p-datatable> </div> in template above far row[col.field] assigned string, gets displayed. if row[col.field] object template doesn't bind. believe template not @ picked, because when inspect html can't see custom tags.
i want bind data @ following level: <h2>{{row[col.field]['someproperty']['finalproperty']}}</h2>
i have used in following way: <h2>{{row[col.field].someproperty.finalproperty]}}</h2>
in each of above case object bound table , table shows [object object]
is not possible bind data in following manner. doing wrong here. kindly suggest..
what do, transform data receive make "readable" datatable.
first, should have data :
let data = [ {name: 'ziggity', surname: 'zwooty', age: 16}, {name: 'bippity', surname: 'bopitty', age: 18}, ]; from data got, should properties of data :
let keys = object.keys(data[0]); // ['name', 'surname', 'age'] now, in html, can repeat primeng component each key :
<div class="col-sm-12 kill-padding table"> <p-datatable [value]="data" rowhover="true"> <p-column *ngfor="let key of keys"> <ng-template ptemplate="body" let-row="rowdata"> <div [ptooltip]="row[key]" tooltipposition="bottom"> <h2>{{row[key]}}</h2> </div> </ng-template> </p-column> </p-datatable> </div>
Comments
Post a Comment