I need assistance with sorting a table either from largest to smallest or alphabetically.
Here is the HTML code of the section I'm trying to sort:
<tr>
<th scope="col" [appSort]="dataList" data-order="desc" data-name="no">
<span (click)="sort()" class="sort-icon d-flex"> No
<mat-icon *ngIf="sorting === 'desc'">keyboard_arrow_down</mat-icon>
<mat-icon *ngIf="sorting === 'asc'">keyboard_arrow_up</mat-icon>
</span>
</th>
<th scope="col" [appSort]="dataList" data-order="desc" data-name="id">
<span (click)="sort()" class="sort-icon d-flex">Id
<mat-icon *ngIf="sorting === 'desc'">keyboard_arrow_down</mat-icon>
<mat-icon *ngIf="sorting === 'asc'">keyboard_arrow_up</mat-icon>
</span>
</th>
<th scope="col" [appSort]="dataList" data-order="desc" data-name="type">Tür</th>
<th scope="col" [appSort]="dataList" data-order="desc" data-name="additional">Ek</th>
<th scope="col" [appSort]="dataList" data-order="desc" data-name="media">Medya
</th>
</tr>
**Additionally, here is the related TypeScript function:**
sorting = "desc"
sort() {
if (this.sorting == "desc") {
this.sorting = "asc"
} else {
this.sorting = "desc"
}
}
I am facing an issue where when I sort by 'NO', the arrow in 'ID' also moves. How can I resolve this problem?
My preference is that clicking on 'NO' should only affect the arrow there and not interfere with 'ID'.
Note: This is my first query here, so feedback is appreciated if I have overlooked anything.