[英]How to show string of array in the first column of primeng table in angular
I have a string of array and I want to display that array in first column of the table like this我有一个数组字符串,我想像这样在表格的第一列中显示该数组
c1 c2 c3 c4 c5 c6
d1 - - - - -
d2 - - - - -
d3 - - - - -
d4 - - - - -
the string of array is like this数组的字符串是这样的
data: string[] = ['d1', 'd2', 'd3', 'd4',];
so here is my html code所以这是我的 html 代码
<p-table [columns]="panel.headers" [value]="panel.data">
<ng-template pTemplate="header" let-columns>
<tr *ngFor="let headerRow of panel.headers">
<th *ngFor="let col of headerRow.cols" [attr.colspan]="col.colspan"
[attr.rowspan]="col.rowspan">
{{col.label}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-row>
<tr>
<td *ngFor="let col of panel.headers[panel.headers.length-1].cols"
class="{{row[col.dataClasses]}}">
{{row[col.valueField]}}
</td>
</tr>
</ng-template>
</p-table>
See the stackblitz https://stackblitz.com/edit/primeng-tabledynamic-demo-h58rsj in this example, I want to print tiers in the first column.请参阅此示例中的 stackblitz https://stackblitz.com/edit/primeng-tabledynamic-demo-h58rsj ,我想在第一列中打印层。 please help to solve this.. Thanks
请帮助解决这个问题..谢谢
Just add the column at the beginning:只需在开头添加列:
<ng-template pTemplate="body" let-row>
<tr>
<td>my array goes here</td>
<td *ngFor="let col of panel.headers[panel.headers.length-1].cols"
class="{{row[col.dataClasses]}}">
{{row[col.valueField]}}
</td>
</tr>
</ng-template>
And in your header:在您的 header 中:
<ng-template pTemplate="header" let-columns>
<tr *ngFor="let headerRow of panel.headers">
<th></th>
<th *ngFor="let col of headerRow.cols" [attr.colspan]="col.colspan"
[attr.rowspan]="col.rowspan">
{{col.label}}
</th>
</tr>
</ng-template>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.