angular-datatables icon indicating copy to clipboard operation
angular-datatables copied to clipboard

component using angular datatable and dttrigger when switch between components it gives error of ObjectUnsubscribedError because of dttriggers.next()

Open awais2080 opened this issue 8 years ago • 6 comments

rerender(): void {
        this.dtElement.dtInstance.then((dtInstance: DataTables.Api) => {
          // Destroy the table first
          dtInstance.destroy();
          // Call the dtTriggers to rerender again
         this.dtTriggers.next();
        });
}

ngOnDestroy(){
        console.log("dashboard destroy is called");
        this.dtTriggers.unsubscribe();
}

image

awais2080 avatar May 18 '18 17:05 awais2080

plz help me how can i resolve it i have been struggling with this for week almost

awais2080 avatar May 18 '18 17:05 awais2080

Can you edit this sample to reproduce your issue?

l-lin avatar May 27 '18 10:05 l-lin

I created sample. For reproduce, you must click Show/Hide button.

Sir-J avatar Jun 22 '18 05:06 Sir-J

Unfortunately, when using ngIf, it destroys completely the DOM, so the dtTrigger is also destroyed, thus the error. One way to hide/show the table is to use the hidden property instead. Check this example. I do not have any other solution :/

l-lin avatar Jul 08 '18 14:07 l-lin

Maybe need to create a component and in component use your directive? ngIf = false hide the component and destroy DOM. ngIf = true reinitialize the component and create new DOM. The component creates new dtTrigger.

Sir-J avatar Jul 09 '18 04:07 Sir-J

Unfortunately, when using ngIf, it destroys completely the DOM, so the dtTrigger is also destroyed, thus the error. One way to hide/show the table is to use the hidden property instead. Check this example. I do not have any other solution :/

I tried to use the [hidden], but it is showing me error

DataTables warning: table id=releaseDatatable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

alwinaugustin avatar Jul 17 '20 06:07 alwinaugustin