角度7-重新加载数据表中的数据

时间:2019-03-17 17:24:07

标签: angular datatable refresh rerender

我正在将angular 7与angular-datatables一起使用。 我正试图定义一个“渲染”按钮,以便重新加载数据like in this example

我不明白我应该在render函数中放置什么:

我的API函数:

fn_getFavoriteTables() {

  this._getFavoriteTablesApiCall =  this.getFavoriteTablesService.getFavoriteTables(Number(localStorage.getItem('UserID')), Number(localStorage.getItem('BranchID'))).pipe(takeUntil(this.destroySubject$)).subscribe(x => {
        this.getFavoriteTables = x;
        this.dtTrigger.next();
    });

};

渲染功能:

rerender(): void {
    this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
        // Destroy the table first 

        dtInstance.destroy();


        // Call the dtTrigger to rerender again
        this.dtTrigger.next();
    });
}

ngOnDestroy(): void {
  console.log('ngDestroy');
  // Do not forget to unsubscribe the event
  this.dtTrigger.unsubscribe();
}

3 个答案:

答案 0 :(得分:2)

这也可以这样完成:

ifconfig ("qfec0 lladdr 00:11:22:33:44:55")

答案 1 :(得分:1)

找到了一个对我有用的答案: this is the source site

const mongoose = require('mongoose');

async ()=> {
    await mongoose.connection.on('connected', ()=>{
        const gridfs = require('mongoose-gridfs')({
            collection: 'sharedfiles',
            model: 'SharedFiles',
            mongooseconnection: mongoose.connection
        });
        global.sharedfile = gridfs;
    });
module.exports = sharedfile;
} 

答案 2 :(得分:0)

您可以使用 DataTable destroy() API 删除表并重新使用 dtTrigger 重新渲染表。请检查以下链接。

https://l-lin.github.io/angular-datatables/#/advanced/rerender