Billy
Billy

Reputation: 1067

Using PrimeNG DataTables

Trying to setup DataTable from PrimeNG. I get the response back from the API like this

[{"firstName":"Mop","lastName":"Top","eId":"aaa123","tech":"AWS"},{"firstName":"Hey","lastName":"Arnold","eId":"hfg456","tech":"AWS"},{"firstName":"Hom","lastName":"Mom","eId":"abf654","tech":"AWS"}]

It seems I might be using ngFor wrong because it does not load the array to the table ? There is no error in the console so I'm not sure exactly I'm doing wrong.

Link to my code

Yes I know Datatable is deprecated but I could not get TableModule to import :(

Upvotes: 0

Views: 1762

Answers (1)

Jon
Jon

Reputation: 116

You only use *ngFor with p-columns if you want your table's columns to be dynamic. Judging by your code, your columns are not defined in the typescript at all, therefore they should be defined statically in your html:

<p-dataTable [value]="tech">
  <p-column field="firstName" header="First Name"></p-column>
  <p-column field="lastName" header="Last Name"></p-column>
  <p-column field="eId" header="E Id"></p-column>
  <p-column field="tech" header="Tech"></p-column>
</p-dataTable>

In PrimeNG's documentation, this information is under the first "Source" tab, right under "Basic".

Upvotes: 1

Related Questions