Experimented with the following approach:
if (field == 'age') {
if (this.sortedAge) {
this.fltUsers.sort(function (a, b) {
if (b.totalHours > a.totalHours) {
return 1;
}
});
this.sortedAge = false;
} else {
this.sortedAge = true;
this.fltUsers.sort(function (a, b) {
if (b.totalHours < a.totalHours) {
return 1;
}
});
}
}
I have an array of objects where each object contains a property: totalHours
.
The objective is to sort this array by the field totalHours
in ascending or descending order upon clicking.
Unfortunately, my current implementation is not functioning as intended.