Angular slickgrid not displaying inside dynamic ta

2019-08-24 09:41发布

问题:

I am using Angular Slickgrid to display table data inside tabs. I have a html page where two tabs are static also displaying data correctly and other tabs are dynamically created from a dedicated tab at the end which is basically build a query from the inputs and when you save the tab it will create a new tab, append it after the 2nd tab and send the query to the newly generated tab which will fetch record from the service with the given query. I am getting data from the service successfully but the table is not displaying anything not even table heading. Here is the code:

Parent html:

   <tabset #tabsetId>
    <tab heading="heading1" id="1" (selectTab)="onSelectTab($event)">
       <child-component [query]="query"></child-component>
    </tab>

    <tab heading="heading2" id="2" (selectTab)="onSelectTab($event)">
       <child-component [query]="query"></child-component>
    </tab>

    <!--below tab is not displaying any data -->
    <tab id="3" *ngFor="let tabz of tabs" [heading]="tabz.title" [active]="tabz.active"
    (selectTab)="onSelectTab($event)" (deselect)="tabz.active = false" [disabled]="tabz.disabled"
    [removable]="tabz.removable" (removed)="removeTabHandler(tabz)">
    <child-component [query]="query"></child-component>
    </tab>
</tabset>
    <!-- Note: Child component is having angular slick grid code -->

Child code html:

<div style="height:auto;width:750px">
   <angular-slickgrid gridId="grid1" [columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions"
   [dataset]="responseList" (onAngularGridCreated)="angularGridReady($event)">
   </angular-slickgrid>
</div>

Child component:

    export class ChildComponent {
      @Input() query: Array<any>;
      ngOnInit() {
        this.columnDefinitions = [
          { col- 1},{ col - 2 }
       ]
    this.gridOptions = {
      enableAutoResize: true,
      enableCellNavigation: true,
      enableFiltering: true,
      forceFitColumns: true
    }
    this.fetchData(this.query);
    }

    angularGridReady(angularGrid: AngularGridInstance) {
     console.log('slickgrid created');
      }

      private fetchData(query: Array<any>) {
        // Clearing response list
        this.responseList = [];
          this.service.fetchDataByQuery(query).subscribe(responseList => {
          this.responseList = responseList;
          });

      }
    }

回答1:

In your child-component.html, i can see that you are passing same gridId everytime to the angular-slickgrid tag. Instead, you can pass a unique Id each time as a angular input, from your parent component.

Finally, your child and parent htmls snippets looks like below.

Parent html:

<child-component [id]="id" [query]="query"></child-component>

Child html:

<angular-slickgrid [gridId]="id" [columnDefinitions]="columnDefinitions" [gridOptions]="gridOptions"
   [dataset]="responseList" (onAngularGridCreated)="angularGridReady($event)">
   </angular-slickgrid>

Happy coding.