angular 7 - reload data in data table

前端 未结 2 1544
忘掉有多难
忘掉有多难 2021-01-19 05:36

I\'m using angular 7 with angular-datatables. I\'m tring to define a \"rerender\" button in order to reload data like in this example.

I don\'t understand what shoul

相关标签:
2条回答
  • 2021-01-19 06:32

    Found an answer that worked for me: this is the source site

     rerender(): void {
        this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
            // Destroy the table first 
            //debugger;
            var table = $('#favoriteTable').DataTable();
    
            $('#tableDestroy').on('click', function () {
                table.destroy();
            });
    
            dtInstance.destroy();
    
            this.fn_getFavoriteTables();
    
        });
    }
    
    0 讨论(0)
  • 2021-01-19 06:39

    This can also be done like this:

    import { DataTableDirective } from 'angular-datatables';
    
    dtElement: DataTableDirective;
    dtInstance: Promise<DataTables.Api>;
    
    rerender(): void  {
      this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
        dtInstance.ajax.reload()
      });
    }
    
    0 讨论(0)
提交回复
热议问题