ng2-smart-table - данные новой строки пусты после добавления строки

Для ng2-smart-table после добавления строки данные, отображаемые в таблице, были пустыми, но я могу отредактировать пустую строку и сохранить, а также удалить.

данные, отображаемые в event.newData, пусты

(createConfirm)="onCreateConfirm($event) --> не работает

(editConfirm)="onSaveConfirm($event) --> в порядке

(deleteConfirm)="onDeleteConfirm($event) --> в порядке

пустая строка в таблице

Надеюсь, кто-то может помочь Заранее спасибо

  1. .html

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

  1. .ts

        data = [];

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

        },
        delete: {
          confirmDelete: true,
          deleteButtonContent: '<i class="nb-trash"></i>',

        },
        columns: {
          jobProcessId: {
            title: 'ID',
            type: 'number',
            width: '100px',
          },
          processName: {
            title: 'Job Process Name',
            type: 'string',

          },
          processDescription: {
            title: 'Job Process Description',
            type: 'string',
            width: 'auto',

          },
        },
      };

      source: LocalDataSource = new LocalDataSource();
      constructor(private jobProcess: JobProcessService) {

        this.jobProcess.list().subscribe((res: any[]) => {
          this.data = res;
          console.log(this.data);
          this.source.load(this.data);
        } );

      }

      ngOnInit() {
      }

      onCreateConfirm(event) {
        console.log(event.newData);
        if (window.confirm('Are you sure you want to create?')) {
          event.confirm.resolve();
        } else {
          event.confirm.reject();
        }
      }
      onDeleteConfirm(event) {
        if (window.confirm('Are you sure you want to delete?')) {
          event.confirm.resolve();
        } else {
          event.confirm.reject();
        }

      }

        onSaveConfirm(event) {
        if (window.confirm('Are you sure you want to save?')) {
            event.confirm.resolve();
          } else {
            event.confirm.reject();
          }
      }


person Surasak Kaewsiri    schedule 05.07.2019    source источник


Ответы (1)


используйте это для своего html

 <ng2-smart-table [settings]="settings" [source]="source" 
(createConfirm)="onCreateConfirm($event)"

(deleteConfirm)="onDeleteConfirm($event)"
(editConfirm)="onSaveConfirm($event)">

 </ng2-smart-table>

*компоненты*

settings = {delete: {
  confirmDelete: true
},
add: {
  confirmCreate: true
},
edit: {
  confirmSave: true
},
 .......
}
source: LocalDataSource;
 constructor() {
this.source = new LocalDataSource(this.data);
}
 onDeleteConfirm(event):void {
 if (window.confirm('Are you sure you want to delete?')) {



  event.confirm.resolve(); 
  } else {
event.confirm.reject();
 }

}

onSaveConfirm(event):void {
  if (window.confirm('Are you sure you want to save?')) {
 event.newData['name'] += ' + added in code'; 
 event.confirm.resolve(event.newData);
 } else {
 event.confirm.reject();
}
  onCreateConfirm(event):void { 
  event.confirm.resolve(event.newData);
  }











  




 
 

 
person Ayush Singh    schedule 05.07.2019
comment
Я пытался использовать этот код до event.confirm.resolve(event.newData);, но дело в том, что event.newData пусто, я не знаю, почему - person Surasak Kaewsiri; 05.07.2019