In my angular project and by using primeNg table I want to delete row after confirmation, so every row has a delete button when click on it the confirmation message showing, but the problem when click on confirm button the last row in the table deleted, not the same row was selected.
This my HTML :
<button class="btn btn-danger" (click)="showConfirm()"><span class="fa fa-trash"></span></button>
<p-toast position="center" key="c" (onClose)="onReject()" [modal]="true" [baseZIndex]="5000">
<ng-template let-message pTemplate="message">
<div style="text-align: center">
<i class="pi pi-exclamation-triangle" style="font-size: 3em"></i>
<h3>{{message.summary}}</h3>
<p>{{message.detail}}</p>
</div>
<div class="ui-g ui-fluid">
<div class="ui-g-6">
<button type="button" pButton (click)="onConfirm(rowData.id)" label="yes" class="ui-button-success"></button>
</div>
<div class="ui-g-6">
<button type="button" pButton (click)="onReject()" label="No" class="ui-button-secondary"></button>
</div>
</div>
</ng-template>
</p-toast>
in components.ts i use this methods:
showConfirm() { // to show confirm massage
this.messageService.add({key: 'c', sticky: true, severity:'warn', summary:'!Delete confirm', detail:'Are you shur to dlelete this client '});
}
onConfirm(id:Clients) {
this.Service.deleteClient(id).subscribe(res => {})
onReject() {
this.messageService.clear('c');
}
referance of primeNg:[https://www.primefaces.org/primeng/#/toast]
Update
when I try to put the parameter rowData.id in showConfirm method in HTML and in components.ts showConfirm(id:Clients) and use concatenation in massage detail showing the selected row,
HTML
<button class="btn btn-danger" (click)="showConfirm(rowData.id)"><span class="fa fa-trash"></span></button>
components.ts
showConfirm(id:Clients) { // to show confirm massage
this.messageService.add({key: 'c', sticky: true, severity:'warn', summary:'!Delete confirm', detail:'Are you shur to dlelete this client '+id});
}
but i dont know how to pass the same parameter from showConfirm(id:Clients) to onConfirm() method.
rowData.idcould you check-update, please. - Mohamed Elkast