I used ng2 smart table
in my angular 2 project, I need to send an API
request using http.post()
method when a new row is added to table. How can I get the value of each cell in the newly added row?
Asked
Active
Viewed 1,798 times
2

Ampati Hareesh
- 1,852
- 1
- 15
- 20

parisa ghabel
- 21
- 2
1 Answers
3
HTML
<ng2-smart-table
[settings]="settings"
[source]="data"
(createConfirm)="onPostCall($event)"
(editConfirm)="onPostCall($event)">
</ng2-smart-table>
For calling post method on both editing and creating new row
settings [TS]:
settings = {
add: {
confirmCreate: true,
},
edit: {
confirmSave: true,
},
columns:{
// your fields and titles here
}
}
On update[TS]
onPostCall(event){
event.confirm.resolve(event.newData);
// console.log(event.newData); //this contains the new edited data
//your post request goes here
// example
const req = http.post('/api/items/add', body);
// 0 requests made - .subscribe() not called.
req.subscribe();
// 1 request made.
}
Ref : https://akveo.github.io/ng2-smart-table/#/examples/various

Ampati Hareesh
- 1,852
- 1
- 15
- 20