0

I am following this but my case is slightly different with dynamic data (both Element and Columns) from Api let's say

Element_Data

{name: 'Hydrogen', weight: 1.0079, symbol: 'H'}

displayedColumn

["name","weight","symbol"]

In my case I loop into displayedColumn like this and push to column

for(var x = 0 ;x<this.displayedColumns.length;x++){

  this.columns.push( {columnDef: this.displayedColumns[x], header: this.displayedColumns[x],    cell: 
 (element: any) => `${ element.date}`});
}

 this.displayedColumns = this.columns.map(c => c.columnDef);

 this.DataSet  =  Observable.of(this.Element_Data);

Problem

This problem is with this statement

${ element.date}`}

as I am using dynamic data I cannot write static property name for each element it should be dynamic something like

 {this.displayedColumns[x]}

so that the correct value will return on calling

<mat-cell *cdkCellDef="let row">{{ column.cell(row) }}</mat-cell>

I have also checked this but no luck in this case of "column as property name"

Please help me solve this.

TAHA SULTAN TEMURI
  • 4,031
  • 2
  • 40
  • 66

1 Answers1

1

element.date is equivalent to element['date'] so you can put any string object inside it. Source

  • good approach but it is not working in this scenario , the result is undefined in case of dynamic but fine in case of static string type inside array , but it gives me a hint voting up – TAHA SULTAN TEMURI Dec 04 '19 at 06:31