Edit and create with ng2-smart-table
Asked Answered
D

2

9

I am trying to use <ng2-smart-table>. The issue is that I don't know how to bind the plus button (addButtonContent) with some create function data. Now this just opens for me anther row to insert the data. Also how can I do it for the edit button. My code is:

settings = {
   add: {
      addButtonContent: '<i class="ion-ios-plus-outline"></i>', //how to call some function to this one
      createButtonContent: '<i class="ion-checkmark"></i>',
      cancelButtonContent: '<i class="ion-close"></i>',
   },
   edit: {
      editButtonContent: '<i class="ion-edit"></i>',
      saveButtonContent: '<i class="ion-checkmark"></i>',
      cancelButtonContent: '<i class="ion-close"></i>',
   },
   delete: {
      deleteButtonContent: '<i class="ion-trash-a"></i>',
      confirmDelete: true
   },

and my template is:

<ba-card title="Basic Example" baCardClass="with-scroll">
   <div class="form-group">
      <input  #search type="search" class="form-control form-control-lg" placeholder="Search..."  (keyup)="onSearch(search.value)">
   </div>
   <ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)"></ng2-smart-table>
</ba-card>
Doty answered 3/11, 2016 at 14:39 Comment(0)
S
12

in your template add this

     <ng2-smart-table class='form-control' [settings]="settings" [source]="source"  (deleteConfirm)="onDeleteConfirm($event)" (editConfirm)="onSaveConfirm($event)"
 (createConfirm)="onCreateConfirm($event)"  ></ng2-smart-table> 

and then in your component call the new actions

onCreateConfirm(event):void { 
} 

onSaveConfirm(event):void {
}

onDeleteConfirm(event): void {
}
Shondrashone answered 10/11, 2016 at 14:54 Comment(1)
Check @alvarosmh answer below as well to get the complete solution !Marisolmarissa
S
6

I wanted to comment on Yousef Al Kahky's answer but im new so i have to answer again:

You also have to add confirmCreate: true, otherwise the method won't be invoked.

add: {
  addButtonContent: '<i class="nb-plus"></i>',
  createButtonContent: '<i class="nb-checkmark"></i>',
  cancelButtonContent: '<i class="nb-close"></i>',
  confirmCreate: true,
},
Seventy answered 17/6, 2019 at 0:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.