我正在使用ng2-smart-table
在angular 6应用中显示数据。现在,我无法获取删除事件。我已经设置了这样的设置对象。
columns: {
... // Columns...
},
edit: {
confirmSave: true,
editButtonContent: '...',
saveButtonContent: '...',
cancelButtonContent: '...'
},
delete: {
confirmDelete : true,
deleteButtonContent: '...',
saveButtonContent: '...',
cancelButtonContent: '...'
},
在HTML文件中,我对此进行了设置。
<ng2-smart-table [settings]="Settings" [source]="DataSource" (createConfirm)="onCreate($event)" (confirmDelete)="onRoleDelete($event)"></ng2-smart-table>
在.ts文件中
onRoleDelete(event) {
alert("Delete works");
}
我检查了它的git
并也参考了其他示例。我也能够获得编辑事件,但不能仅获得删除事件。
删除图标也在HTML
文件中查看。
答案 0 :(得分:1)
尝试使用deleteConfirm
代替confirmDelete
请参考Demo以获得更好的理解
删除mode: 'external',
<ng2-smart-table [settings]="settings" [source]="DataSource" (createConfirm)="onCreate($event)" (deleteConfirm)="onRoleDelete($event)"></ng2-smart-table>
配置:
settings = {
delete: {
confirmDelete: true,
},
add: {
confirmCreate: true,
},
edit: {
confirmSave: true,
},
columns: {
id: {
title: 'ID',
},
name: {
title: 'Full Name',
},
username: {
title: 'User Name',
},
email: {
title: 'Email',
},
},
};
data = [
{
id: 1,
name: "Leanne Graham",
username: "Bret",
email: "Sincere@april.biz"
},
{
id: 2,
name: "Ervin Howell",
username: "Antonette",
email: "Shanna@melissa.tv"
},
// ... list of items
{
id: 11,
name: "Nicholas DuBuque",
username: "Nicholas.Stanton",
email: "Rey.Padberg@rosamond.biz"
}
];
onDeleteConfirm(event) {
console.log("Delete Event In Console")
console.log(event);
if (window.confirm('Are you sure you want to delete?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}
onCreateConfirm(event) {
console.log("Create Event In Console")
console.log(event);
}
onSaveConfirm(event) {
console.log("Edit Event In Console")
console.log(event);
}