简体   繁体   English

如何在 angular 的primeng表的第一列中显示数组字符串

[英]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.

相关问题 Angular PrimeNG 10 显示,而不是切换,可扩展的表格行 - Angular PrimeNG 10 show, not toggle, expandable table row 如何仅在 angular 的表中显示匹配的列 - How to show matched column only in table in angular 如何将 PrimeNg Tree 表中的列组与不可滚动列组合在一起? - How to combine column groups in PrimeNg Tree table with unscrollable column? 如何在 angular 8 中的表格中显示特定列的鼠标 hover 的特定数据 - How to show specific data on mouse hover of specific column into table in angular 8 如何在 angular 8 悬停时显示来自 json 的表列数据 - How to show the table column data coming from json on hover in angular 8 如何在角度6的表格的单独列中显示多个行值的总和? - How to Show total of multiple row values in to separate column of the table in angular 6? 首先按布尔列排序数组,然后按字符串列排序 - Sort an array first by boolean column then by string column 如何根据Angular JS中的表数组在下拉列表中获取列? - How to get column in drop down according to table array in angular js? select 的复选框 angular 底漆表中的所有复选框 - checkbox for select all checkboxes in angular primeng table 如何使用angular2 primeng使子元素在搜索中显示并在全部单击时显示所有元素 - How to make child elements to display on search and show all elements on click of All using angular2 primeng
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM