如何在 ng2-smart-table 中删除一行
How to delete a row in ng2-smart-table
我正在做一个 angular 项目。我在我的项目中使用 ng2-smart-table
作为 table。我已经连接到 google cloud firestore
,现在我可以使用 firestore 添加和检索数据。我想选择删除行。
我该怎么做?
我将上面提到的 table 添加到制造组件中。
manufacture.component.ts
import { Component, OnInit } from '@angular/core';
import { ManufactureService } from './manufacture.service';
import { Manufacture } from './manufacture.model';
@Component({
selector: 'ngx-manufacture',
styles: [],
template: `
<ng2-smart-table
(createConfirm)="addData($event)"
(deleteConfirm)="deleteData($event)"
[settings]="settings"
[source]="manu"
>
</ng2-smart-table>
`
})
export class ManufactureComponent implements OnInit {
manu: Manufacture[] = [];
constructor(private service: ManufactureService) {}
ngOnInit() {
alert(this.service.show());
this.service.getManufacture().subscribe(arr => {
let manu_list = arr.payload.get('manufact');
if (manu_list) {
this.manu = manu_list;
}
});
}
settings = {
add: {
addButtonContent: '<i class="nb-plus"></i>',
createButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmCreate: true
},
edit: {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>'
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
confirmDelete: true
},
columns: {
shopname: {
title: 'Shop Name'
},
ownername: {
title: 'Owner Name'
},
nic: {
title: 'NIC'
},
contactno: {
title: 'ContactNo'
},
address: {
title: 'Address'
},
email: {
title: 'Email'
}
}
};
addData(data) {
this.manu.push(data.newData);
console.log(this.manu);
this.service.addManufacture({ manufact: this.manu }).subscribe(next => {
data.confirm.reject();
});
}
deleteData(data) {
this.service.deleteManufacture();
}
}
我可以删除整个文档,但我只想删除特定的一行。
deleteSpecificRow(event) {
this.service.deleteTheRow(event.data.id);
}
我认为您已经实现了使用 id 删除单行的服务 (deleteTheRow),希望这会有所帮助!
deleteTheRow() 函数:
deleteTheRow(id) {return
this.firestore
.collection("yourCollection")
.manu(id)
.delete();}
- 我想你应该看看这个:
https://itnext.io/how-to-crud-in-angular-firebase-firestore-456353d7c62
我正在做一个 angular 项目。我在我的项目中使用 ng2-smart-table
作为 table。我已经连接到 google cloud firestore
,现在我可以使用 firestore 添加和检索数据。我想选择删除行。
我该怎么做?
我将上面提到的 table 添加到制造组件中。
manufacture.component.ts
import { Component, OnInit } from '@angular/core';
import { ManufactureService } from './manufacture.service';
import { Manufacture } from './manufacture.model';
@Component({
selector: 'ngx-manufacture',
styles: [],
template: `
<ng2-smart-table
(createConfirm)="addData($event)"
(deleteConfirm)="deleteData($event)"
[settings]="settings"
[source]="manu"
>
</ng2-smart-table>
`
})
export class ManufactureComponent implements OnInit {
manu: Manufacture[] = [];
constructor(private service: ManufactureService) {}
ngOnInit() {
alert(this.service.show());
this.service.getManufacture().subscribe(arr => {
let manu_list = arr.payload.get('manufact');
if (manu_list) {
this.manu = manu_list;
}
});
}
settings = {
add: {
addButtonContent: '<i class="nb-plus"></i>',
createButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>',
confirmCreate: true
},
edit: {
editButtonContent: '<i class="nb-edit"></i>',
saveButtonContent: '<i class="nb-checkmark"></i>',
cancelButtonContent: '<i class="nb-close"></i>'
},
delete: {
deleteButtonContent: '<i class="nb-trash"></i>',
confirmDelete: true
},
columns: {
shopname: {
title: 'Shop Name'
},
ownername: {
title: 'Owner Name'
},
nic: {
title: 'NIC'
},
contactno: {
title: 'ContactNo'
},
address: {
title: 'Address'
},
email: {
title: 'Email'
}
}
};
addData(data) {
this.manu.push(data.newData);
console.log(this.manu);
this.service.addManufacture({ manufact: this.manu }).subscribe(next => {
data.confirm.reject();
});
}
deleteData(data) {
this.service.deleteManufacture();
}
}
我可以删除整个文档,但我只想删除特定的一行。
deleteSpecificRow(event) {
this.service.deleteTheRow(event.data.id);
}
我认为您已经实现了使用 id 删除单行的服务 (deleteTheRow),希望这会有所帮助!
deleteTheRow() 函数:
deleteTheRow(id) {return
this.firestore
.collection("yourCollection")
.manu(id)
.delete();}
- 我想你应该看看这个: https://itnext.io/how-to-crud-in-angular-firebase-firestore-456353d7c62