Skip to content
Snippets Groups Projects
Commit fc76ef9f authored by D4rkHeart's avatar D4rkHeart
Browse files

[Feat] Birth dates are now sorted correctly

parent 079f08e0
No related branches found
No related tags found
1 merge request!20Sorting by birth date not working
......@@ -26,6 +26,7 @@
:pagination.sync="pagination"
:select-all="$store.getters['moduleUser/userIsResponsible']"
:search="$store.state.moduleApplications.filters.search"
:custom-sort="customSort"
>
<template v-slot:items="props">
<span></span>
......@@ -211,7 +212,36 @@ export default {
dateTimeParts[1]--
let date = new Date(...dateTimeParts)
return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' à ' + ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2)
}
},
customSort: function (items, index,isDesc) {
if (items.length === 0 || index.length === 0) {
return items;
}
const column = index;
const descending = isDesc;
const compareAlphabetically = (a, b) => {
return a[column] < b[column] ? (descending ? -1 : 1) : (descending ? 1 : -1);
};
//Sort by date
const compareByDate = (a, b) => {
const dateA = new Date(a[column].split('/').reverse().join('-'));
const dateB = new Date(b[column].split('/').reverse().join('-'));
return descending ? dateA - dateB : dateB - dateA;
};
let compareFunction;
if (column === 'applicant_birthdate') {
compareFunction = compareByDate;
} else {
compareFunction = compareAlphabetically;
}
items.sort(compareFunction);
return items;
},
},
components: {
ApplicationsFilters,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment