Khaleel Mohamed
Khaleel Mohamed

Reputation: 25

ngx-datatables element of arrays

I have arrays of elements within a structure:

rsDoorInfo
{
  tDoorNumArray:["701","702",...,"800"],
  tStartDate:["17-JUN-2018 15:51:00",","17-JUN-2018 15:51:00",...,"17-JUN-2999 15:51:00"],
  tEndDate:["17-JUN-2019 15:51:00", "17-JUN-2019 15:51:00",...,"17-JUN-2019 15:51:00"]
}

There are a 100 elements within each array. I am having trouble displaying this data on an ngx-datatable. I would like to be displayed as:

Door Number | Start Date | End Date

Is there any way of doing this without changing the data structure? Thank you.

Upvotes: 0

Views: 5006

Answers (1)

Bruno João
Bruno João

Reputation: 5525

You can use a template inside the datatable-column so you can extract any info form the row object.

Use the tDoorNumArray as your aray in the table rows. Inside each row, you can get the index and so access the data by the index

<ngx-datatable [rows]="rsDoorInfo.tDoorNumArray">
  <ngx-datatable-column name="Door Number">
    <ng-template let-row="row" let-rowIndex="rowIndex">
      {{ row }}
    </ng-template>
  </ngx-datatable-column>

  <ngx-datatable-column name="Start Date">
    <ng-template let-row="row" let-rowIndex="rowIndex">
      {{ rsDoorInfo.tStartDate[rowIndex] }}
    </ng-template>
  </ngx-datatable-column>
</ngx-datatable>

It let you use the current structure but I recommend you to map this data so your view does not have to find all data for each table row.

Upvotes: 3

Related Questions