My table's column sorting feature works well with first name and last name, but it seems to have issues with dl and dl score columns. I need assistance in fixing this problem.
To access the code, click here: https://stackblitz.com/edit/angular-ivy-87hi8i?file=src%2Fapp%2Fapp.component.html
sort(property: any) {
this.isDesc = !this.isDesc;
this.column = property;
let direction = this.isDesc ? 1 : -1;
this.allUser.sort(function(
a: { [x: string]: number },
b: { [x: string]: number }
) {
if (a[property] < b[property]) {
return -1 * direction;
} else if (a[property] > b[property]) {
return 1 * direction;
} else {
return 0;
}
});
}
markup
<tr>
<th *ngIf="!isEdit">Edit</th>
<th [ngClass]="{pointer: true, active:column=='first_name',desc:isDesc, asc:!isDesc}"
(click)="sort('first_name')">First Name</th>
<th [ngClass]="{pointer: true, active:column=='last_name',desc:isDesc, asc:!isDesc}"
(click)="sort('last_name')">Last Name</th>
<th>Email</th>
<th>Gender</th>
<th>DOB</th>
<th>Impact</th>
<th>Score</th>
<th [ngClass]="{pointer: true, active:column=='dl',desc:isDesc, asc:!isDesc}" (click)="sort('dl')">
DL</th>
<th [ngClass]="{pointer: true, active:column=='co_score',desc:isDesc, asc:!isDesc}"
(click)="sort('co_score')">DL Score</th>
<th></th>
</tr>