First column repeating in both froze & unfroze table in Primeng table

蓝咒 提交于 2019-12-11 15:41:19

问题


I am working on one project where I used PrimeNg table with froze & unfroze column property and its working fine in normal column creating with *NgFor but if I add new column without *NgFor its repeating in both froze & unfroze table.

How to overcome this issue as I want that column only on froze column not on unfroze column.

My Code:

<ng-template pTemplate="header" let-columns>
    <tr>
      <th>All</th>
      <th *ngFor="let col of columns">
        {{col.header}}
      </th>
    </tr>
  </ng-template>
  <ng-template pTemplate="body" let-rowData let-columns="columns">
    <tr>
      <td>
                <p-tableCheckbox
                  [value]="rowData"
                  [attr.disabled]="
                    rowData.setupType === 'No Action' &&
                    rowData.currentStatus === 'INACTIVE'
                      ? 'disabled'
                      : null
                  "
                ></p-tableCheckbox>
              </td>
      <td *ngFor="let col of columns">
        {{rowData[col.field]}}
      </td>
    </tr>
  </ng-template>

Column repeat Issue:

How to overcome this issue ?

Guide me if its possible in PrimeNg table.


回答1:


You need to use template frozenheader

<ng-template pTemplate="frozenheader" let-columns>
        <tr>
            <th>All</th>
            <th *ngFor="let col of columns">
                {{col.header}}
            </th>
        </tr>
    </ng-template>

and frozenbody

<ng-template pTemplate="frozenbody" let-rowData let-columns="columns">
        <tr>
            <td style="text-align: center">
                <p-tableCheckbox [value]="rowData" [attr.disabled]="
                    rowData.setupType === 'No Action' &&
                    rowData.currentStatus === 'INACTIVE'
                      ? 'disabled'
                      : null
                  "></p-tableCheckbox>
            </td>
            <td *ngFor="let col of columns">
                {{ rowData[col.field] }}
            </td>
        </tr>
    </ng-template>

Demo here



来源:https://stackoverflow.com/questions/54211196/first-column-repeating-in-both-froze-unfroze-table-in-primeng-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!