I have a problem deleting a row from a p-datatable
.
TS
public files: UploadFile[] = [];
deleteAttachement(index) {
if (this.files.length > 0) {
for(let file2 of this.files) {
if (file2.fileEntry.isFile) {
const fileEntry = file2.fileEntry as FileSystemFileEntry;
fileEntry.file((file: File) => {
console.log("-------------");
console.log("File: "+file.name);
});
}
}
this.files.splice(index, 1);
for(let file2 of this.files) {
if (file2.fileEntry.isFile) {
const fileEntry = file2.fileEntry as FileSystemFileEntry;
fileEntry.file((file: File) => {
console.log("_______________");
console.log("File: "+file.name);
});
}
}
}
}
HTML
<p-dataTable [value]="files" *ngIf="files.length > 0">
<p-column>
<ng-template let-index="rowIndex" pTemplate type="body">
<p-button (onClick)="deleteAttachement(index)" icon="fa fa-fw fa-close"></p-button>
</ng-template>
</p-column>
</p-dataTable>
My code is logging the right things. It seems I am splicing right. BUT when I want to update the datatable in the view a change the line :
this.files = this.files.splice(index, 1);
But now it splices wrong and it doesn't remove the right row. Sometimes it deletes multiple rows and sometimes it removes nothing.
this.files = this.files.splice(index, 1);
? Where is it? – Bharat Gupta