#MatTableDataSource with array

12 messages · Page 1 of 1 (latest)

proper pawn
#

Hi,

I'm displaying some data in a MatTableDataSource but I have the following question.

How do I display the data present in cphas when it can be a 1-to-many array?
I would like to return, on the same line, the name of the data referring to this array.
follow my code

My displayed Columns look like this:

displayedColumns: string[] = ['cpha', 'process', 'appointment', 'arbitration', 'issue', 'performance', 'value', 'duplicity.justification', 'cphas'];

I'm displaying the cphas data like this:

<!-- Symbol Column -->
                      <ng-container matColumnDef="cphas">
                         <th mat-header-cell *matHeaderCellDef> Duplicate with </th>
                         <td mat-cell *matCellDef="let element"> {{element.cphas}}</td>
                     </ng-container>

can anybody help me?

hallow iron
#

Using ngFor?

proper pawn
hallow iron
#

Yes. why not? It all depends on how you want to display those "cphas"?

proper pawn
#

The issue is that cphas brings me the id of the information I want. Through this id I want to display the name of this information in the same column. did you understand?

hallow iron
#

Well, change that. If you need to display names and you only have IDs, you need to change your design so that you get names and not just IDs.

proper pawn
hallow iron
#

Yes. There's nowhere else you can find the names, are there. Instead of returning something like

{
  "foo": "bar"
  "cphas"= [1, 2]
}

the backend should return something like

{
  "foo": "bar"
  "cphas"= [
    { "id": 1, "name": "John" },
    { "id": 2, "name": "Jane" }
  ]
}
proper pawn
hallow iron
#

Well, you have several things to display in an array, and ngFor is used to iterate over an array.