[Vuejs]-Sorting not working for Date field in Vuejs

0👍

To work with dates, you need to use new Date():

sortedCats:function() {
return this.cats.sort((a,b) => {
    aDate = new Date(a[this.currentSort]);
    bDate = new Date(b[this.currentSort]);
    let modifier = 1;
    if(this.currentSortDir === 'desc') modifier = -1;
    if(aDate < bDate) return -1 * modifier;
    if(aDate > bDate) return 1 * modifier;
    return 0;
}).filter((row, index) => {
    let start = (this.currentPage-1)*this.pageSize;
    let end = this.currentPage*this.pageSize;
    if(index >= start && index < end) return true;
});

}

Leave a comment