0

I'm displaying a primeng table and the cell format will depend on the next column value, i.e. the one beside it to the right.

I'm wondering how I can get the value of another column. I have:

         <p-column *ngFor="let col of cols" [field]="col.field" [header]="col.header">

          <ng-template let-row="rowData" pTemplate="body" *ngIf="col.field!='Name'">

            {{row[col.field]}} --displays current cell. I want to compare value to value of cell beside it

          </ng-template>

        </p-column>

if "row[col.field]" gives me the value of the current column cell value, how can I get cell beside it?

Any ideas?

thegunner
  • 6,883
  • 30
  • 94
  • 143

1 Answers1

1

If you know the column name (eg id) of another column, then {{row['id']}}.

Or if you know the order in which other columns appear (eg 0), then {{row[cols[0].field]}}.

<p-column *ngFor="let col of cols" [field]="col.field [header]="col.header">    
  <ng-template let-row="rowData" pTemplate="body" *ngIf="col.field!='Name'">
          {{row[col.field]}}     --displays current cell.
          {{row['id']}}          --displays cell which column name is 'id'.
          {{row[cols[0].field]}} --displays first column cell.
  </ng-template>
</p-column>
kenji
  • 11
  • 2