我正在做一个有角度的项目。我在项目中使用ng2-smart-table
作为表格。我已经连接到google cloud firestore
,现在可以使用firestore添加和检索数据。我想选择删除行。
我该怎么做?
我将上述表格添加到制造组件中。
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();
}
}
我可以删除整个文档,但是我只想删除特定的一行。
答案 0 :(得分:1)
Microsoft.Office.Interop.Excel.Worksheet sheet1 in ActiveWorkbook.Worksheets
我认为您已经实现了使用id删除一行的服务(deleteTheRow),希望对您有所帮助!
deleteTheRow()函数:
deleteSpecificRow(event) {
this.service.deleteTheRow(event.data.id);
}
-我想您应该看一下: https://itnext.io/how-to-crud-in-angular-firebase-firestore-456353d7c62