要删除Angular2-datatable中的行,您可以使用以下步骤:
import { DataTable } from 'angular2-datatable';
data = [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' },
{ id: 3, name: 'Doe' }
];
ID
Name
Action
{{row.id}}
{{row.name}}
deleteRow
方法来删除行:deleteRow(id: number) {
// 在data数组中查找并删除指定ID的行
const index = this.data.findIndex(row => row.id === id);
if (index !== -1) {
this.data.splice(index, 1);
}
}
这样,当您点击"Delete"按钮时,将调用deleteRow
方法并从data
数组中删除相应的行。
请注意,columns
和rows
是DataTable组件的输入属性,您需要根据您的数据结构进行相应的调整。