feat: ajout d'une nouvelle cle dans le header :
``` "filtreColValeurs" : { "domaines" : [(#CONST{_DOMAINES_INTERVENTION}|json_encode)] }, ``` cela permet de forcer les valeurs du select pour le tri des colonnes
This commit is contained in:
parent
56ce585ff9
commit
e5133a834a
3 changed files with 79 additions and 30 deletions
|
@ -21,6 +21,9 @@
|
||||||
"statut" : "select",
|
"statut" : "select",
|
||||||
"titre": "input"
|
"titre": "input"
|
||||||
},
|
},
|
||||||
|
"filtreColValeurs" : {
|
||||||
|
"domaines" : [(#LISTE{valeur1, valeur2}|json_encode)]
|
||||||
|
},
|
||||||
"classes":{
|
"classes":{
|
||||||
"titre": "toto",
|
"titre": "toto",
|
||||||
"email":"toto"
|
"email":"toto"
|
||||||
|
|
|
@ -480,6 +480,8 @@ let trierVal = props.trier;
|
||||||
|
|
||||||
let nameLocalStorage = calculer_nameLocalStorage();
|
let nameLocalStorage = calculer_nameLocalStorage();
|
||||||
|
|
||||||
|
let filtreColValeurs = [];
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
localforage.setDriver(localforage[props.stockage.toUpperCase()]);
|
localforage.setDriver(localforage[props.stockage.toUpperCase()]);
|
||||||
chargerJson("maj");
|
chargerJson("maj");
|
||||||
|
@ -550,9 +552,35 @@ const tableau = computed(() => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// on test si on vient d'un filtrage avec recup des valeurs en header
|
||||||
|
if (filtreColValeurs[colName]) {
|
||||||
if (
|
if (
|
||||||
ligne[champ_search.value][colName] !==
|
ligne[champ_search.value][
|
||||||
undefined &&
|
colName
|
||||||
|
] !== undefined &&
|
||||||
|
!(
|
||||||
|
ligne[champ_search.value][
|
||||||
|
colName
|
||||||
|
]
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
.toString()
|
||||||
|
.indexOf(uneValeur) ===
|
||||||
|
-1 ||
|
||||||
|
!ligne[champ_search.value][
|
||||||
|
colName
|
||||||
|
]
|
||||||
|
.toString()
|
||||||
|
.toLowerCase()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (
|
||||||
|
ligne[champ_search.value][
|
||||||
|
colName
|
||||||
|
] !== undefined &&
|
||||||
!(
|
!(
|
||||||
uneValeur.indexOf(
|
uneValeur.indexOf(
|
||||||
ligne[champ_search.value][
|
ligne[champ_search.value][
|
||||||
|
@ -562,7 +590,9 @@ const tableau = computed(() => {
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.toString()
|
.toString()
|
||||||
) === -1 ||
|
) === -1 ||
|
||||||
!ligne[champ_search.value][colName]
|
!ligne[champ_search.value][
|
||||||
|
colName
|
||||||
|
]
|
||||||
.toString()
|
.toString()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
)
|
)
|
||||||
|
@ -570,6 +600,7 @@ const tableau = computed(() => {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (!Trsearch) {
|
if (!Trsearch) {
|
||||||
rsearch = false;
|
rsearch = false;
|
||||||
|
@ -685,6 +716,14 @@ function gererConfig(config) {
|
||||||
if (config.filtreCol !== undefined) {
|
if (config.filtreCol !== undefined) {
|
||||||
filtreCol = config.filtreCol;
|
filtreCol = config.filtreCol;
|
||||||
}
|
}
|
||||||
|
if (config.filtreColValeurs !== undefined) {
|
||||||
|
filtreColValeurs = config.filtreColValeurs;
|
||||||
|
// Object.keys(filtreColVal.value).forEach((col) => {
|
||||||
|
// if (filtreColValeurs[col]) {
|
||||||
|
// filtreColVal.value[col] = filtreColValeurs[col];
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
}
|
||||||
saveHeader();
|
saveHeader();
|
||||||
return filtreCol;
|
return filtreCol;
|
||||||
}
|
}
|
||||||
|
@ -735,6 +774,10 @@ function filtrerCol(filtreColRecup) {
|
||||||
filtreColType.value = filtreColRecup;
|
filtreColType.value = filtreColRecup;
|
||||||
filtreCol.value = [];
|
filtreCol.value = [];
|
||||||
Object.keys(filtreColType.value).forEach((col) => {
|
Object.keys(filtreColType.value).forEach((col) => {
|
||||||
|
filtreCol.value.push(col);
|
||||||
|
if (filtreColValeurs[col]) {
|
||||||
|
filtreColVal.value[col] = filtreColValeurs[col];
|
||||||
|
} else {
|
||||||
let Tval = [];
|
let Tval = [];
|
||||||
table.value.forEach((t) => {
|
table.value.forEach((t) => {
|
||||||
let valCol = t[champ_search.value][col];
|
let valCol = t[champ_search.value][col];
|
||||||
|
@ -744,8 +787,8 @@ function filtrerCol(filtreColRecup) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
filtreCol.value.push(col);
|
|
||||||
filtreColVal.value[col] = Tval.sort();
|
filtreColVal.value[col] = Tval.sort();
|
||||||
|
}
|
||||||
filtreColSelected.value[col] = [];
|
filtreColSelected.value[col] = [];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,23 +12,26 @@ function recupJson(d) {
|
||||||
try {
|
try {
|
||||||
return JSON.parse(d);
|
return JSON.parse(d);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('erreur recupJson ', e);
|
console.log("erreur recupJson ", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function navigate(href, newTab) {
|
function navigate(href, newTab) {
|
||||||
let a = document.createElement('a');
|
let a = document.createElement("a");
|
||||||
a.href = href;
|
a.href = href;
|
||||||
if (newTab) {
|
if (newTab) {
|
||||||
a.setAttribute('target', '_blank');
|
a.setAttribute("target", "_blank");
|
||||||
}
|
}
|
||||||
a.click();
|
a.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
function ordonnerSelect(a, b) {
|
function ordonnerSelect(a, b) {
|
||||||
// attention ! le test d'égalité en == et non pas === est voulu tel quel...
|
// attention ! le test d'égalité en == et non pas === est voulu tel quel...
|
||||||
if ((Number.isInteger(a) || parseInt(a) == a) && (Number.isInteger(b) || parseInt(b) == b)) {
|
if (
|
||||||
|
(Number.isInteger(a) || parseInt(a) == a) &&
|
||||||
|
(Number.isInteger(b) || parseInt(b) == b)
|
||||||
|
) {
|
||||||
return parseInt(a) - parseInt(b);
|
return parseInt(a) - parseInt(b);
|
||||||
} else {
|
} else {
|
||||||
let x = toString(a).toLowerCase();
|
let x = toString(a).toLowerCase();
|
||||||
|
@ -48,18 +51,18 @@ const orderBy = (arr, props, orders, champ) =>
|
||||||
props.reduce((acc, prop, i) => {
|
props.reduce((acc, prop, i) => {
|
||||||
if (acc === 0) {
|
if (acc === 0) {
|
||||||
let [p1, p2] =
|
let [p1, p2] =
|
||||||
orders && orders[i] === 'desc'
|
orders && orders[i] === "desc"
|
||||||
? [b[champ][prop], a[champ][prop]]
|
? [b[champ][prop], a[champ][prop]]
|
||||||
: [a[champ][prop], b[champ][prop]];
|
: [a[champ][prop], b[champ][prop]];
|
||||||
// passe en lowercase les String
|
// passe en lowercase les String
|
||||||
p1 = typeof p1 === 'string' ? p1.toLowerCase() : p1;
|
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
|
// Gestion du format de date
|
||||||
// transforme 03/11/2000 en 20001103
|
// transforme 03/11/2000 en 20001103
|
||||||
let re = /^(\d{2})\/(\d{2})\/(\d{2,4})$/;
|
let re = /^(\d{2})\/(\d{2})\/(\d{2,4})$/;
|
||||||
|
|
||||||
if (typeof p1 !== 'number') {
|
if (typeof p1 !== "number") {
|
||||||
let r1 = p1.match(re);
|
let r1 = p1.match(re);
|
||||||
if (Array.isArray(r1)) {
|
if (Array.isArray(r1)) {
|
||||||
p1 = r1[3] + r1[2] + r1[1];
|
p1 = r1[3] + r1[2] + r1[1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue