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

203
Views
Can I somehow change the order of the tables to be displayed?

I have three tables

<table class="table1">
   ...
   <tbody>
      <tr *ngFor="let data of datasource1">
      ...
      </tr>
   </tbody>
</table>
<table class="table2">
   ...
   <tbody>
      <tr *ngFor="let data of datasource2">
      ...
      </tr>
   </tbody>
</table>
<table class="table3">
   ...
   <tbody>
      <tr *ngFor="let data of datasource3">
      ...
      </tr>
   </tbody>
</table>

and I want to somehow be in control of which table should be displayed in which order, i.e., first table3 then table1 then table2 (or some other order). How would I do that?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Templates can be created for each table and rendered in the required order based on a condition.

Create table templates:

<ng-template name="table1">
  <table class="table1">
   ...
   <tbody>
      <tr *ngFor="let data of datasource1">
      ...
      </tr>
   </tbody>
  </table>
</ng-template>

... similarly for table2, 3

I am assuming there is a variable order in your component.ts file which defines the order to use. And

  1. If it's value is 1: order of tables is 1, 2, 3
  2. If it's value is 2: order is 2, 3, 1
  3. If it's value is 3: order is 3, 1, 2

So the html to render in required order could be one of the following as per your case

1.

<ng-container *ngIf="order === 1">
   <ng-container *ngTemplateOutlet="table1">
   <ng-container *ngTemplateOutlet="table2">
   <ng-container *ngTemplateOutlet="table3">
</ng-container>

<ng-container *ngIf="order === 2">
   <ng-container *ngTemplateOutlet="table2">
   <ng-container *ngTemplateOutlet="table3">
   <ng-container *ngTemplateOutlet="table1">
</ng-container>

Note: *ngIf needs to be updated with required condition
.... other conditions
   <ng-container *ngTemplateOutlet="order === 1 ? table1 : order === 2 ? table2 : table3">
   <ng-container *ngTemplateOutlet="order === 1 ? table2 : order === 2 ? table3 : table1">
   <ng-container *ngTemplateOutlet="order === 1 ? table3 : order === 2 ? table1 : table2">
over 4 years ago · Santiago Trujillo Report

0

You can use CSS, wrap the tables in a div and apply flex box - display: flex; Assign tot each table an order - order: 0; order:1; and so on.

over 4 years ago · Santiago Trujillo 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!