Created
September 16, 2019 15:36
-
-
Save Lodo4ka/fd35607a30cf03fc37e9b95c75ce23e7 to your computer and use it in GitHub Desktop.
custom table with my sort any data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (event.target.classList[0] === "points") { | |
this.toggleSortTable.points ? this.users.sort((a, b) => b.points_earned - a.points_earned) : this.users.sort((a, b) => a.points_earned - b.points_earned); | |
this.toggleSortTable.points = !this.toggleSortTable.points; | |
} else if (event.target.classList[0] === "name") { | |
if(this.toggleSortTable.name) { | |
this.users.sort(function (a, b) { | |
if (a.name < b.name) { | |
return 1; | |
} | |
if (a.name > b.name) { | |
return -1; | |
} | |
}); | |
} | |
else { | |
this.users.sort(function (a, b) { | |
if (a.name > b.name) { | |
return 1; | |
} | |
if (a.name < b.name) { | |
return -1; | |
} | |
}); | |
} | |
this.toggleSortTable.name = !this.toggleSortTable.name; | |
} else if(event.target.classList[0] === "date") { | |
if(this.toggleSortTable.date) { | |
this.users.sort((a, b) => { | |
const dateA = new Date(a.registration_date); | |
const dateB = new Date(b.registration_date); | |
return dateB - dateA; | |
}); | |
} else { | |
this.users.sort((a, b) => { | |
const dateA = new Date(a.registration_date); | |
const dateB = new Date(b.registration_date); | |
return dateA - dateB; | |
}); | |
} | |
this.toggleSortTable.date = !this.toggleSortTable.date; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment