0

I have a table which take its values from tablesValue.

<p-table [value]="tablesValue">

I need to support "delete all change that the user can do on table". So at start I copy the tablesValue into tablesValueBackup. When the user clicks on a button, I show a dialog:

<p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"></p-confirmDialog>

In ts, I do:

    click(){
     let tablesValue=this.tablesValue;
        let tablesValueBackup=this.tablesValueBackup;
        this.confirmationService.confirm({
          message: 'Delete all change',
          accept: () => {
            //the problem is here because the table is not update
            tablesValue= tablesValueBackup;
            console.log(tablesValue);
          }
        });
    }

Why when I click on accept button in confirm button, the table is not updated in UI but in console.log it prints the correct value?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Postilla
  • 161
  • 1
  • 1
  • 8

1 Answers1

0

Try this!

You just confused with same variable names

click(){
let tablesValue=this.tablesValue;
    const tablesValueBackupLocal=JSON.parse(JSON.stringify(this.tablesValueBackup));
    this.confirmationService.confirm({
      message: 'Delete all change',
      accept: () => {
        //the problem is here because the table is not update
        this.tablesValue= tablesValueBackup;
        console.log(this.tablesValue);
      }
    });
}
Rama Krishna
  • 645
  • 10
  • 28