I have a requirement where in a HTML table I have to sort the table's values based on a property name. Please refer the code below
<h2>{{modifiedBy}} {{order}}</h2>
<table class="table table-striped border mt-1">
<thead>
<tr>
<th scope="col" (click)="sortBy('id', 'desc')">Id <i *ngIf="modifiedBy!=='id'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='desc' && modifiedBy==='id'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='asc' && modifiedBy==='id'" class="fa fa-arrow-up"></i>
</th>
<th scope="col" (click)="sortBy('name', 'desc')">Name
<i *ngIf="modifiedBy!=='name'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='desc' && modifiedBy==='name'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='asc' && modifiedBy==='name'" class="fa fa-arrow-up"></i>
</th>
<th scope="col" (click)="sortBy('age', 'desc')">Age
<i *ngIf="modifiedBy!=='age'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='desc' && modifiedBy==='age'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='asc' && modifiedBy==='age'" class="fa fa-arrow-up"></i>
</th>
<th scope="col" (click)="sortBy('dob', 'desc')">Date Of Birth
<i *ngIf="order==='asc' && modifiedBy==='dob'" class="fa fa-arrow-down"></i>
<i *ngIf="order==='desc' && modifiedBy==='dob'" class="fa fa-arrow-up"></i>
</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of dataList | orderBy:modifiedBy:order:dateType">
<td>{{ data.id }}</td>
<td>{{ data.name }}</td>
<td>{{ data.age }}</td>
<td>{{ data.dob }}</td>
</tr>
</tbody>
</table>
On load, the table will be sorted in descending order with the "dob" property and an arrow icon for the "dob" table header cell will have an arrow pointing up and for the rest it will be pointing down (asc:arrow down, desc:arrow up).
Now what I want to do whenever I click any table header cell which is to be sorted is to sort the table data based on the clicked table header cell's property and the arrow icon should change based on the sort order that is asc or desc. Please note that while sorting a table head, it should not disturb the arrow icons of the other table header cells.
I have put up some code which is partially working. I can't proceed further as I'm struggling with rest of the logic. Additionally, I'm using two icons conditionally for each table head. Will it possible to use a single icon for each table head?