2016-11-04 155 views
1

我從firebase獲取數據並使用ng2-smart-table顯示數據。 我添加數據後創建按鈕不關閉的問題。它仍然以添加的值打開。 我的代碼是:ng2-smart-table創建按鈕無法正常工作

settings = { 
    pager:{perPage:50}, 
    add: { 
     addButtonContent: '<i class="ion-ios-plus-outline"></i>', 
     createButtonContent: '<i class="ion-checkmark"></i>', 
     cancelButtonContent: '<i class="ion-close"></i>', 
     confirmCreate: true, 


    }, 

和增加的功能:

onCreateConfirm(event): any { 
    //this service is updating the new data to firebase. 
    this.service.createData(event.newData); 
    //after that the newdata still on edit mode and not closing it... 
    } 

回答

1

你必須在onCreateConfirm(事件)的末尾添加此行

event.confirm.resolve(event.newData); 
+0

但這將自動添加到表,也是我的函數添加這火力地堡db,然後它會自動更新2個實例的表,從firebase和其他的解決。 –

+0

我不明白你的問題,你能給我更多的解釋 –

+0

問題是,我將這個新的數據添加到Firebase列表。這個列表綁定到表中的數據源,然後在表中更新它,然後如果我會按照你的方式更新表的功能,我將有2個實例,一個是解析和其他的虛擬結果一個由firebase名單。 –

1

中添加這您template 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); 
    } 
+0

這不是廁所ks正確,因爲它的觸發器onCreateConfirm一旦用戶點擊加號,並且應該在用戶填充所有數據後才觸發 –

+1

用於自定義添加/編輯/刪除功能的舊帖子 –

+0

我不認爲你是對的!你沒有閱讀這篇文章。它將表2寫入表2的問題,因爲它綁定到Firebase列表並執行解決。 –

0

的問題是在該表的組合angularfire,我認爲它的某種錯誤。
我正在使用AngularFire2測試表格,並且遇到同樣的問題。爲了避免這種(自制)的唯一方法是:

settings = { 
    pager: { 
     perPage: 1000 
    }... // More settings, add, edit, actions, etc 

當U編輯,並觸發保存按鈕它重新加載所有,但如果重裝的大小+原始大小比pager.perPage下限ü不需額外看到重複的東西。這是我的方法:

onEditConfirm(event): void { 
    console.log(event.data); // Testing only 
    console.log(event.newData); // Testing only 
    this.af.database.object('Usuarios/' + 
    event.data.nif.toLowerCase()).set({ 
     email: event.data.email, 
     nombre: event.newData.nombre, 
     nif: event.data.nif, 
     rol: event.data.rol 
    }); 
    this.source.update(event.data, event.newData); //it update well 
    event.confirm.resolve(event.newData); 
} 

現在,如果我們假設我們有70行會複製到140,但如果u有一個更高的值pager.perPage財產U將不會看到重複的項目。測試。然而it'sa壞的解決方案,但我真的覺得it'sa smarttables

的錯誤希望它可以幫助5個月後^^」