Skip to content

Instantly share code, notes, and snippets.

@Lodo4ka
Created September 16, 2019 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lodo4ka/fd35607a30cf03fc37e9b95c75ce23e7 to your computer and use it in GitHub Desktop.
Save Lodo4ka/fd35607a30cf03fc37e9b95c75ce23e7 to your computer and use it in GitHub Desktop.
custom table with my sort any data
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