如何解决角料表总是删除第一行
我有一个包含一些数据的表格和一个所有行的删除功能,它可以工作但总是删除第一行,如果我单击其他行上的删除按钮总是删除实际的第一行,则无关紧要。
这是我的代码:
public deleteRow(recordId) {
console.log('recordId: ',recordId); // log: undefined
const dsData = this.dataSource.data;
console.log('dsData: ',dsData); // log: list all the data I have in table
// For delete confirm dialog in deleteItem to match the db column name to fetch.
const name1 = 'id';
const record = dsData.find(obj => obj[this.Users.id] === recordId);
const name = 'Delete record with id:' + record[name1] + '?';
console.log('Record is: ',record); // log: all the data of the first row
console.log('Record id is: ',recordId); // log: undefined
// Call the confirm dialog component
this.confirmService.confirm(name,record,'This action will delete the record!').pipe(
switchMap(res => {if (res === true) {
console.log('recordId: ',recordId); // log: undefined
return this.httpClientService.deleteRow(record);
}}))
.subscribe(
result => {
this.success();
// Refresh DataTable to remove row.
this.deleteRowDataTable (recordId,this.Users.id,this.paginator,this.dataSource);
},(err: HttpErrorResponse) => {
console.log(err.error);
console.log(err.message);
this.messagesService.openDialog('Error','Delete did not happen.');
}
);
}
// Remove the deleted row from the data table. Need to remove from the downloaded data first.
private deleteRowDataTable (recordId,idColumn,paginator,dataSource) {
this.dsData = dataSource.data;
const itemIndex = this.dsData.findIndex(obj => obj[idColumn] === recordId);
dataSource.data.splice(itemIndex,1);
dataSource.paginator = paginator;
}
问题出在我在日志中看到的 Id 上,但我不知道如何修复它
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。