diff --git a/json_gamutable.json.html b/json_gamutable.json.html
index 412ad4f..4bda44a 100644
--- a/json_gamutable.json.html
+++ b/json_gamutable.json.html
@@ -21,6 +21,9 @@
"statut" : "select",
"titre": "input"
},
+"filtreColValeurs" : {
+ "domaines" : [(#LISTE{valeur1, valeur2}|json_encode)]
+},
"classes":{
"titre": "toto",
"email":"toto"
diff --git a/src/components/gamuTable.vue b/src/components/gamuTable.vue
index c6f0ffb..e516386 100644
--- a/src/components/gamuTable.vue
+++ b/src/components/gamuTable.vue
@@ -480,6 +480,8 @@ let trierVal = props.trier;
let nameLocalStorage = calculer_nameLocalStorage();
+let filtreColValeurs = [];
+
onMounted(() => {
localforage.setDriver(localforage[props.stockage.toUpperCase()]);
chargerJson("maj");
@@ -550,24 +552,53 @@ const tableau = computed(() => {
return true;
}
} else {
- if (
- ligne[champ_search.value][colName] !==
- undefined &&
- !(
- uneValeur.indexOf(
+ // on test si on vient d'un filtrage avec recup des valeurs en header
+ if (filtreColValeurs[colName]) {
+ if (
+ ligne[champ_search.value][
+ colName
+ ] !== undefined &&
+ !(
ligne[champ_search.value][
colName
]
.toString()
.toLowerCase()
.toString()
- ) === -1 ||
- !ligne[champ_search.value][colName]
- .toString()
- .toLowerCase()
- )
- ) {
- return true;
+ .indexOf(uneValeur) ===
+ -1 ||
+ !ligne[champ_search.value][
+ colName
+ ]
+ .toString()
+ .toLowerCase()
+ )
+ ) {
+ return true;
+ }
+ } else {
+ if (
+ ligne[champ_search.value][
+ colName
+ ] !== undefined &&
+ !(
+ uneValeur.indexOf(
+ ligne[champ_search.value][
+ colName
+ ]
+ .toString()
+ .toLowerCase()
+ .toString()
+ ) === -1 ||
+ !ligne[champ_search.value][
+ colName
+ ]
+ .toString()
+ .toLowerCase()
+ )
+ ) {
+ return true;
+ }
}
}
});
@@ -685,6 +716,14 @@ function gererConfig(config) {
if (config.filtreCol !== undefined) {
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();
return filtreCol;
}
@@ -735,17 +774,21 @@ function filtrerCol(filtreColRecup) {
filtreColType.value = filtreColRecup;
filtreCol.value = [];
Object.keys(filtreColType.value).forEach((col) => {
- let Tval = [];
- table.value.forEach((t) => {
- let valCol = t[champ_search.value][col];
- if (valCol) {
- if (Tval.indexOf(valCol) === -1) {
- Tval.push(valCol);
- }
- }
- });
filtreCol.value.push(col);
- filtreColVal.value[col] = Tval.sort();
+ if (filtreColValeurs[col]) {
+ filtreColVal.value[col] = filtreColValeurs[col];
+ } else {
+ let Tval = [];
+ table.value.forEach((t) => {
+ let valCol = t[champ_search.value][col];
+ if (valCol) {
+ if (Tval.indexOf(valCol) === -1) {
+ Tval.push(valCol);
+ }
+ }
+ });
+ filtreColVal.value[col] = Tval.sort();
+ }
filtreColSelected.value[col] = [];
});
}
diff --git a/src/components/helpers.js b/src/components/helpers.js
index 0370bc7..0893626 100644
--- a/src/components/helpers.js
+++ b/src/components/helpers.js
@@ -12,23 +12,26 @@ function recupJson(d) {
try {
return JSON.parse(d);
} catch (e) {
- console.log('erreur recupJson ', e);
+ console.log("erreur recupJson ", e);
return false;
}
}
function navigate(href, newTab) {
- let a = document.createElement('a');
+ let a = document.createElement("a");
a.href = href;
if (newTab) {
- a.setAttribute('target', '_blank');
+ a.setAttribute("target", "_blank");
}
a.click();
}
function ordonnerSelect(a, b) {
// 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);
} else {
let x = toString(a).toLowerCase();
@@ -48,18 +51,18 @@ const orderBy = (arr, props, orders, champ) =>
props.reduce((acc, prop, i) => {
if (acc === 0) {
let [p1, p2] =
- orders && orders[i] === 'desc'
+ orders && orders[i] === "desc"
? [b[champ][prop], a[champ][prop]]
: [a[champ][prop], b[champ][prop]];
// passe en lowercase les String
- p1 = typeof p1 === 'string' ? p1.toLowerCase() : p1;
- p2 = typeof p2 === 'string' ? p2.toLowerCase() : p2;
+ 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})\/(\d{2})\/(\d{2,4})$/;
- if (typeof p1 !== 'number') {
+ if (typeof p1 !== "number") {
let r1 = p1.match(re);
if (Array.isArray(r1)) {
p1 = r1[3] + r1[2] + r1[1];