l-lin / angular-datatables

DataTables with Angular
https://l-lin.github.io/angular-datatables/
MIT License
1.57k stars 486 forks source link

Opening child row doesn't call Child's OnInit #1665

Closed pponzano closed 2 years ago

pponzano commented 2 years ago

:beetle: bug report

When opening detail row, no onInit or AfterViewInit is fired

:microscope: Minimal Reproduction

StackBlitz/GitHub Link:

Step-by-step Instructions:

:8ball: Expected behavior

I'm opending a detail mode with the following code

 expandRow(trRef: any, rowData: any) {
    this.datatableElement.dtInstance.then((dtInstance: DataTables.Api) => {
      const row = dtInstance.row(trRef);

      if (row.child.isShown()) {
        row.child.hide();
        this._renderer.removeClass(trRef, 'details');
      }
      else {
        row.child()

        let factory = this.compFactory.resolveComponentFactory(SupplierSourceChildComponent);
        var component = this.viewRef.createComponent(factory);

        //  component.instance.itemSource = rowData;
        row.child(component.location.nativeElement).show();
        this._renderer.addClass(trRef, 'details');
      }
    }, (err) => {
      console.log(err)
      this.notifyService.showError(
        err.statusText,
        'Error while inserting item.'
      )
    }
    )
  }

and in the child OnViewIniti nothing is fired. I need to load the data in the child row to populate another grid but with no luck.

:globe_with_meridians: Your Environment

:memo: Additional context

shanmukhateja commented 2 years ago

Hi,

Can you provide StackBlitz link instead?

pponzano commented 2 years ago

Hello, I've read on this on internet, it seems that OnInit and AfterViewActivated are not called when the component is created dinamically, so I had to perform the call of methods in the constructor