Angular ngx-datatable row-detail issues
Asked Answered
C

2

7

I'm having two issues with using row-detail in ngx-datatable.

  1. rowIndex is not working. I found a github issue describing the problem but it was supposedly fixed around v. 10.0.2 and I'm using 11.1.5 (the current version). Every row returns 0 for {{rowIndex}}. My workaround is to write out my own index to a column and then reference that, but I shouldn't have to do that. With the code below, every row goes into edit mode when I click one of them, because they all have the same rowIndex.

  2. I can't get the row-details rows to use the full-width of their 'parent' rows. I suspect it's because I'm using [columnMode]="'flex'" whereas the demo uses columnMode]="'force'". I can set a min-width, but I can't get width: 100% to work. Possibly because there's a div wrapper with no width

<ngx-datatable #dataTable class="material expandable" [rows]="rows" [limit]="50" [columnMode]="'flex'"
  [headerHeight]="50" [footerHeight]="50" [rowHeight]="50" [selectionType]="'single'" (select)="onSelect($event)"
  (activate)="onActivate($event)">
  <!-- Row Detail Template -->
  <ngx-datatable-row-detail [rowHeight]="50" #myDetailRow (toggle)="onDetailToggle($event)">
    <ng-template let-rowIndex="rowIndex" let-row="row" let-value="value" let-expanded="expanded"
      ngx-datatable-row-detail-template>
      <span class="rowDetail" title="Click to edit" (click)="editing[rowIndex + '-name'] = true"
        *ngIf="!editing[rowIndex + '-name']"> {{row.name}} </span>
      <mat-form-field floatPlaceholder='never' *ngIf="editing[rowIndex + '-name']">
        <input matInput style="min-width:300px" (keyup.enter)="updateValue($event, 'name', rowIndex)" type="text"
          [value]="row.name" />
      </mat-form-field>
    </ng-template>
    ...
Colostomy answered 14/12, 2017 at 0:55 Comment(1)
/deep/ .datatable-row-detail{ width:250px !important; }Arzola
I
0

Try adding below to your styles.scss or styles.css file. This will force the detail row to use 100% width. However, this is just a workaround and there has been no solution provided by the developer(s).

datatable-scroller { width: 100% !important; }

Iraidairan answered 2/4, 2020 at 7:58 Comment(0)
H
0

Add below to "styles.scss" and add [columnMode]="'force'" to ng-template

<ng-template let-rowIndex="rowIndex" let-row="row" let-value="value" let-expanded="expanded" [columnMode]="'force'" ngx-datatable-row-detail-template>

.datatable-scroller {width: 100% !important; }
Hummel answered 13/10, 2020 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.