Search code examples
angulardatatableprimengprimeng-datatabletwo-way-binding

PrimeNG DataTable Editor shows wrong value


I face an issue about Datatable Editor

My table is datatable of PrimeNG, this table can edit any cell of row and all cell is required:

here is the requiment of Datatable:

  • can edit any cell
  • validate any cell (required)

when I finished 2 requirements, the datatable raise up an issue, and this issue is in the image below enter image description here

please help me out of this issue

and here is Plunker

Here is the importance of Code:

<input [(ngModel)]="data[col.field]" pInputText required="true" [name]="col.field" />

if I add attribute [ngModelOptions]="{standalone: true}" the issue will be resolved but the validation will be removed.


Solution

  • You just made a mistake in the name attribute. Replace

    <input [(ngModel)]="data[col.field]" pInputText required="true" [name]="col.field" />
    

    with

    <input [(ngModel)]="data[col.field]" pInputText required="true" [name]="data[col.field]" />
    

    In your case, col.field equals name so for the whole first column, all your inputs have the same name hence the problem.