Skip to content
Snippets Groups Projects
Commit f75eb450 authored by Leonardo Alain Surdez's avatar Leonardo Alain Surdez
Browse files

Merge branch 'features/sortingBirthdate' into 'master'

Sorting by birth date not working

Closes #15

See merge request !20
parents 97bb6811 220f75ac
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>
......@@ -57,6 +58,8 @@
<td>{{ props.item.applicant_mail }}</td>
<td>
{{ props.item.applicant_birthdate }},
</td>
<td>
<span
v-if="props.item.applicant_has_majority"
>&#10004;</span>
......@@ -140,7 +143,8 @@ export default {
{ text: 'Maturité', value: 'applicant_maturity' },
{ text: 'Adresse', value: 'applicant_npa' },
{ text: 'Email', value: 'applicant_mail' },
{ text: 'Date naissance, majeur', value: 'applicant_birthdate' },
{ text: 'Date naissance', value: 'applicant_birthdate' },
{ text: 'Majeur', value: 'applicant_has_majority' },
{ text: 'Nationalité', value: 'applicant_nationality' },
{ text: 'Origine', value: 'applicant_origin' },
{ text: 'Langues', value: 'applicant_languages', sortable: false },
......@@ -204,11 +208,33 @@ export default {
}
},
getFormatedDate (value) {
let dateTimeParts = value.split(/[- :]/)
dateTimeParts[1]--
let date = new Date(...dateTimeParts)
const dateTimePart = value.split(/[- :]/)[1] - 1
const date = new Date(dateTimePart)
return date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() + ' à ' + ('0' + date.getHours()).slice(-2) + ':' + ('0' + date.getMinutes()).slice(-2)
}
},
customSort: function (items, column, descending) {
const compareAlphabetically = (a, b) => {
return a[column] > b[column] ? 1 : -1;
};
//Sort by date
const compareByDate = (a, b) => {
const dateify = (txt) => new Date(txt[column].split('/').reverse().join('-'))
return dateify(a) - dateify(b);
};
const compareFunction = pickCompareFunction(column);
function pickCompareFunction (column) {
if (column === 'applicant_birthdate') return compareByDate;
return compareAlphabetically;
}
const compareFunctionReversed = function(a, b) { return - compareFunction(a, b); };
return [...items].sort(descending ? compareFunction : compareFunctionReversed);
},
},
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