Greetings all and pardon my novice for I am just a mere beginner. I am trying to sort by ascending/ descending by using an @click and switch case. The method below however, does not sort at all. The very method works for every other data type other than the date (of course), which is why I am confused as this indicates yet another problem with the date data type specifically. I know date data types are very finnicky, so if any advice could be spared it would be greatly appreciated. Here is some supporting code for this problem. If anything else is needed please let me know.
<th @click="sort('date')" scope="col">
Date
<div v-if="sortedKey == 'date'">
<i v-if="sortAscending" class="fas fa-arrow-circle-up"></i>
<i v-else class="fas fa-arrow-circle-down"></i>
</div>
</th>
export default {
name: "ServiceTable",
data() {
return {
pageCount: 10,
query: "",
localEntries: [],
sortedKey: "",
sortAscending: false,
};
},
computed: {
computedList() {
if (this.query.length == 0)
return this.localEntries.slice(0, this.pageCount);
let filteredList = this.localEntries
.filter((element) => {
.slice(0, this.pageCount);
return filteredList;
},
},
sort(key) {
this.sortAscending = !this.sortAscending;
this.sortedKey = key;
switch (key) {
case "date":
if (this.sortAscending)
this.localEntries.sort((a, b) =>
a.date > b.date ? 1 : -1
);
else
this.localEntries.sort((a, b) =>
a.date < b.date ? 1 : -1
);
break;
}