I have a use case wherein I have varying number of rows and columns for my table. I also do not have any information about the header names.
I am trying to use the following implementation:
I fetch the reference for the table using @ViewChild('tableref ') tableref ;
I then call a service to fetch the columns list and assign it as:
tableref .columns = colArray
;
This colArray
contains objects having field
and headers
property which automatically get assigned to the table. (This is working fine and I can see the header name in table)
I am then preparing an array of objects data
, where the objects have a property name same as the field name picked from colArray
.
Finally in my html I 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 the template above as far as row[col.field]
is assigned to a string, it gets displayed. However if row[col.field]
is an object the template simply doesn't bind. I believe the template is not at all picked, because when I inspect the html I can't even see the custom tags.
I want to bind some data at following level:
<h2>{{row[col.field]['someProperty']['finalProperty']}}</h2>
I have also used it in following way:
<h2>{{row[col.field].someProperty.finalProperty]}}</h2>
In each of above case an object is bound to table and the table shows [Object object]
Is it not possible to bind the data in the following manner. Am I doing something wrong here. Kindly suggest..