2
votes

I am using PrimeNG DataTable with Angular and the rows are inline editable like the example in documentation[https://www.primefaces.org/primeng/#/table/edit] and I try to except one cell form this editable rows but the problem I use *ngFor to view data in TD element

My HTML :

<ng-template pTemplate="body" let-rowData let-editing="editing" let-ri="rowIndex" let-columns="columns">
    <tr [pSelectableRow]="rowData" [pEditableRow]="rowData">
        <ng-container>
            <td class="ui-resizable-column" *ngFor="let col of columns">
                <p-cellEditor>
                    <ng-template pTemplate="input">
                        <input pInputText type="text" [(ngModel)]="rowData[col.field]"style="width:100%"/>
            </ng-template>
                        <ng-template pTemplate="output">
                            {{ rowData[col.field] }}
                        </ng-template>
                </p-cellEditor>
            </td>

        </ng-container>
    </tr>
</ng-template>

In order to envision the required see this image enter image description here

Thanks in advance for any help

2
could you create a stackblitz example? - StepUp
thanks a lot for your response [stackblitz.com/edit/… - Mohamed Elkast

2 Answers

3
votes

you can just add a property to columns data and base of that property show the p-cellEditor or just static data

this.cols=[
  { field: 'id', header: '#'  },
  { field: 'name', header: 'الاسم' },
  { field: 'phone', header: 'الهاتف' },
  { field: 'address', header: 'العنوان' },
  { field: 'account', header: 'الحساب' , isStatic :true }, // 👈
  { field: 'nots', header: 'ملاحظات', isStatic :true }, // 👈,
];

template

<td *ngFor="let col of columns">
    <p-cellEditor *ngIf="!col.isStatic;else staticTemplate">
       <ng-template pTemplate="input">
        <input pInputText type="text" [(ngModel)]="rowData[col.field]" style="width:100%" />
       </ng-template>
       <ng-template pTemplate="output">
            {{ rowData[col.field] }}
       </ng-template>
    </p-cellEditor>

    <ng-template #staticTemplate>
        {{ rowData[col.field] }}
    </ng-template>
</td>

demo 🚀

2
votes

You can use ngContainer with *ngIf to choose what template should be shown:

<td *ngFor="let col of columns">
    <ng-container *ngIf="col.header != 'ملاحظات'; else noEdit">
        <p-cellEditor>
            <ng-template pTemplate="input">                  
                <input pInputText type="text" 
                    [(ngModel)]="rowData[col.field]"style="width:100%"/>
            </ng-template>
            <ng-template pTemplate="output">
                {{ rowData[col.field] }}
            </ng-template>
        </p-cellEditor>
    </ng-container>

    <ng-template #noEdit>
         {{ rowData[col.field] }}
    </ng-template>
</td>

A complete example can be seen here.