0

Angular data table not refersh after adding some values to list

table

     <p-dataTable class="pc-datatable" [value]="dList[i].contactData" [responsive]="true">

ts file add

  let obj= new ContactData();
obj.conPerson = this.contactDialogForm.get("contPerson").value;
obj.conMode = this.contactDialogForm.get("contMode").value;
obj.conDetail = this.contactDialogForm.get("contDetail").value;
this.dList[this.selectedIndex].contactData.push(obj);

2 Answers 2

1

try this,

this.dList[this.selectedIndex].contactData = [...this.dList[this.selectedIndex].contactData, obj]

This might be happening because, p-dataTable does not get triggered after you update the array. In order to trigger, you need to create new array and put all data into that

Sign up to request clarification or add additional context in comments.

Comments

0

Because you push data to a list, but you do not change its reference and this change may not be detachable by angular. Even though it is a bad practice, this should solve your problem:

  let obj= new ContactData();
  obj.conPerson = this.contactDialogForm.get("contPerson").value;
  obj.conMode = this.contactDialogForm.get("contMode").value;
  obj.conDetail = this.contactDialogForm.get("contDetail").value;
  this.dList[this.selectedIndex].contactData.push(obj);
  // change reference by re-assignment
  this.dList[this.selectedIndex].contactData = [].concat(this.dList[this.selectedIndex].contactData);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.