tri des cols, si c'est un champ date de la forme 03/11/2015 ou 03/22/98 on transforme en 20151103 avant le tri
This commit is contained in:
parent
73edf728a7
commit
50f39bec6c
2 changed files with 34 additions and 2 deletions
|
@ -27,8 +27,24 @@ const orderBy = (arr, props, orders) =>
|
|||
props.reduce((acc, prop, i) => {
|
||||
if (acc === 0) {
|
||||
let [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]];
|
||||
// passe en lowercase les String
|
||||
p1 = typeof p1 === 'string' ? p1.toLowerCase() : p1;
|
||||
p2 = typeof p2 === 'string' ? p2.toLowerCase() : p2;
|
||||
|
||||
// Gestion du format de date
|
||||
// transforme 03/11/2000 en 20001103
|
||||
let re = /^(\d{2,4})\/(\d{2})\/(\d{2,4})$/;
|
||||
|
||||
let r1 = p1.match(re);
|
||||
if (Array.isArray(r1)) {
|
||||
p1 = r1[3] + r1[2] + r1[1];
|
||||
}
|
||||
|
||||
let r2 = p2.match(re);
|
||||
if (Array.isArray(r2)) {
|
||||
p2 = r2[3] + r2[2] + r2[1];
|
||||
}
|
||||
|
||||
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
||||
}
|
||||
return acc;
|
||||
|
|
|
@ -41,10 +41,26 @@ var orderBy = function orderBy(arr, props, orders) {
|
|||
var _ref = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]],
|
||||
_ref2 = _slicedToArray(_ref, 2),
|
||||
p1 = _ref2[0],
|
||||
p2 = _ref2[1];
|
||||
p2 = _ref2[1]; // passe en lowercase les String
|
||||
|
||||
|
||||
p1 = typeof p1 === 'string' ? p1.toLowerCase() : p1;
|
||||
p2 = typeof p2 === 'string' ? p2.toLowerCase() : p2;
|
||||
p2 = typeof p2 === 'string' ? p2.toLowerCase() : p2; // Gestion du format de date
|
||||
// transforme 03/11/2000 en 20001103
|
||||
|
||||
var re = /^(\d{2,4})\/(\d{2})\/(\d{2,4})$/;
|
||||
var r1 = p1.match(re);
|
||||
|
||||
if (Array.isArray(r1)) {
|
||||
p1 = r1[3] + r1[2] + r1[1];
|
||||
}
|
||||
|
||||
var r2 = p2.match(re);
|
||||
|
||||
if (Array.isArray(r2)) {
|
||||
p2 = r2[3] + r2[2] + r2[1];
|
||||
}
|
||||
|
||||
acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue