使用 ng2-smart-table 编辑和创建

Edit and create with ng2-smart-table

我正在尝试使用 <ng2-smart-table>。问题是我不知道如何将加号按钮 (addButtonContent) 与某些创建函数数据绑定。现在这只是为我打开另一行以插入数据。另外我该如何为编辑按钮做这件事。 我的代码是:

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
   },

我的模板是:

<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>

在您的模板中添加此

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

然后在您的组件中调用新操作

onCreateConfirm(event):void { 
} 

onSaveConfirm(event):void {
}

onDeleteConfirm(event): void {
}

我想对 Yousef Al Kahky 的回答发表评论,但我是新人所以我必须再次回答:

您还必须添加confirmCreate: true,否则该方法将不会被调用。

add: {
  addButtonContent: '<i class="nb-plus"></i>',
  createButtonContent: '<i class="nb-checkmark"></i>',
  cancelButtonContent: '<i class="nb-close"></i>',
  confirmCreate: true,
},