ngx-datatable inside other ngx-datatable rowDetail?
Asked Answered
J

1

7

I'm new with Angular 4 and ngx-datatable and I'm getting stuck. Now, I have a ngx-datatable with a simple rowDetail, just like it's shown here. The problem is that I need the rowDetail to contain another ngx-datatable and I don't know if this is even possible.

Could anybody give me some clue?

Thanks in advance!

Jerroldjerroll answered 22/9, 2017 at 12:48 Comment(0)
J
6

Ok, finally it was no big deal at all. I leave here a sample template of this type of table, for people getting stuck as I did:

  <ngx-datatable #myTable class="material expandable" [rows]="rows" columnMode="flex" [headerHeight]="headerHeight"
    [footerHeight]="footerHeight" [rowHeight]="rowHeight" [loadingIndicator]="loadingIndicator" [externalPaging]="true"
    [count]="page.totalElements" [offset]="page.pageNumber" [limit]="page.size" (page)='setPage($event)'>
    <ngx-datatable-row-detail [rowHeight]="150" #myDetailRow (toggle)="onDetailToggle($event)">
      <ng-template let-row="row" let-expanded="expanded" ngx-datatable-row-detail-template>
        <div>
          <ngx-datatable #myDaughter columnMode="flex" [headerHeight]="falsey" [rows]="getDetailRows(row)"
            [footerHeight]="footerHeight" [rowHeight]="rowHeight" [loadingIndicator]="loadingIndicator" [externalPaging]="true"
            [count]="detailRows.length" [offset]="page.pageNumber" [limit]="page.size" (page)='setPage($event)'>
            <ngx-datatable-column name="A" prop="col_a"></ngx-datatable-column>
            <ngx-datatable-column name="B" prop="col_b"></ngx-datatable-column>
            <ngx-datatable-column name="C" prop="col_c"></ngx-datatable-column>
          </ngx-datatable>
        </div>
      </ng-template>
    </ngx-datatable-row-detail>
    <ngx-datatable-column [sortable]="false" [draggable]="false">
      <ng-template let-row="row" let-expanded="expanded" ngx-datatable-cell-template>
        <button md-icon-button [class.datatable-icon-right]="!expanded" [class.datatable-icon-down]="expanded" title="Expand/Collapse Row"
          (click)="toggleExpandRow(row)"></button>
      </ng-template>
    </ngx-datatable-column>
    <ngx-datatable-column name="A" prop="col_a"></ngx-datatable-column>
    <ngx-datatable-column name="B" prop="col_b"></ngx-datatable-column>
    <ngx-datatable-column name="C" prop="col_c"></ngx-datatable-column>
  </ngx-datatable>
Jerroldjerroll answered 23/9, 2017 at 0:46 Comment(2)
I also had to make sure that my row-detail was before any custom columns or else the datatable inside the row-detail wouldn't show for some reason.Drivein
@Nemezih, can you please provide a fiddle to justify your answer.Mejias

© 2022 - 2024 — McMap. All rights reserved.