I have a header table with arrows indicating sorting order, using Bootstrap icons. However, when I click on a column, all columns receive the icon class. Here is an example of what I mean: https://i.sstatic.net/CAS81.png
Below is the code snippet:
HTML ->
<table class="table table-hover">
<thead>
<th (click)="orderBy('username')">Username<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('email')">Email<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('id')">Id<span [ngClass]="displayArrow()"></span></th>
<th (click)="orderBy('roleId')">Role Id<span [ngClass]="displayArrow()"></span></th>
</thead>
<tbody>
<tr *ngFor="let user of usersListData | orderByController: OrderByParams">
<td (click)="onSelectFilterParam(user.username)">{{user.username}}</td>
<td (click)="onSelectFilterParam(user.email)">{{user.email}}</td>
<td (click)="onSelectFilterParam(user.id)">{{user.id}}</td>
<td (click)="onSelectFilterParam(user.roleId)">{{user.roleId}}</td>
</tr>
</tbody>
AppComponent ->
private toggleArrow = 0;
orderBy(columnName: string) {
this.toggleArrow++;
if(this.toggleArrow > 2) {
this.toggleArrow = 0;
}
console.log(this.toggleArrow);
}
displayArrow() {
if(this.toggleArrow === 0) {
return '';
}
else if(this.toggleArrow === 1) {
return 'glyphicon glyphicon-chevron-up';
}
else if(this.toggleArrow === 2) {
return 'glyphicon glyphicon-chevron-down';
}
}
Is it possible to bind the class to just one element?