angularcelleditprimengtreetable

Angular: Call method on edit cell event PrimeNG TreeTable


I have a PrimeNG TreeTable with an editable column quantity

cart.html

<p-treeTable [value]="items" [columns]="cols">
<ng-template pTemplate="body" let-rowNode let-rowData="rowData">
   <tr>
      <td [ttEditableColumn]="rowData.quantity" [ttEditableColumnField] = "quantity">
      <p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
      <p-treeTableCellEditor>
         <ng-template pTemplate="input" >
            <input type="text" [(ngModel)]="quantity">
         </ng-template>
         <ng-template pTemplate="output" >
            {{quantity}}
         </ng-template>
      </p-treeTableCellEditor>
      </td>
   </tr>
</ng-template>
</p-treeTable>

How can one call a method onEdit() after the cell was edited(Enter pressed)?


Solution

  • You should use

    <p-treeTable [value]="items" [columns]="cols" (onEditComplete)="onEdit(event)">
    

    where

    onEdit(event: { field: string, data: any }): void {
      // your code
    }