Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
ng-zorro antd, nz-table dynamic table columns and rows

I have a table where columns and row cells are dynamically set, in the table header th content should be dynamic and also for table body tr maybe contain HTML that contains another component tag.

is there any way to handle that, I have created a component called table and this table has @Input and @Output to be reusable for different usage.

in the ng-zorro documentation, there is no way to use the table data source technique so I can use render functions like react and.

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create two inputs, one for the columns and one for the rows.

To make the columns dynamically you have to send to the column input an array with column objects. There you can set everything that you want. I usually use the tittle and the column function like that:

listOfColumn = [
    {
      title: 'Code',
      compare: (a: User, b: User) => a.code.localeCompare(b.code)
    },
    {
      title: 'Customer',
      compare: (a: User, b: User) => a.name.localeCompare(b.name)
    }
]

The html code to use it is the following:

<thead>
    <tr>
      <th *ngFor="let column of listOfColumn" [nzSortFn]="column.compare">{{ column.title }}</th>
    </tr>
</thead>

And for the data, just send it to other input and set the array as data input for the table and make a loop to display the content:

<nz-table
  #basicTable
  [nzData]="data">
  <thead>
    <tr>
      <th *ngFor="let column of listOfColumn" [nzSortFn]="column.compare">{{ column.title }}</th>
    </tr>
  </thead>
  <tbody>
    <tr *ngFor="let user of basicTable.data">
      <td>{{ user.code }}</td>
      <td>{{ user.name }}</td>
  </tbody>
</nz-table>

I hope I answer your question :D

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!