Reputation: 21
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?
Upvotes: 2
Views: 1838
Reputation: 1872
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
Upvotes: 3