0

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 :(

6
  • Why would you in a world use *ngFor in column definition? Commented Apr 28, 2018 at 19:53
  • You better check PrimeNG docs on how to use tables. Commented Apr 28, 2018 at 19:55
  • @Antoniossss the documentation for datatables shows doing that I believe? Commented Apr 28, 2018 at 20:28
  • No, example in docs does not do *ngFor N times in colums section Commented Apr 28, 2018 at 21:10
  • You do know that *ngFor is a loop construct right ?? Commented Apr 28, 2018 at 21:12

1 Answer 1

1

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".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.