From 60483a2f848f2f33d6fad26406e377003203814e Mon Sep 17 00:00:00 2001 From: tofulm Date: Fri, 8 May 2020 14:46:07 +0200 Subject: [PATCH] =?UTF-8?q?Apres=20pas=20mal=20de=20tests,=20l'utilisation?= =?UTF-8?q?=20de=20regex=20pour=20r=C3=A9cup=C3=A9rer=20un=20data-search?= =?UTF-8?q?=3D"toto"=20n'est=20pas=20jouable,=20gros=20pb=20de=20performan?= =?UTF-8?q?ce=20sur=20un=20gros=20tableau.=20les=20regex=20OUI=20mais=20si?= =?UTF-8?q?=20pas=20beaucoup=20;-)=20Il=20semble=20indispensable=20de=20po?= =?UTF-8?q?uvoir=20gerer=20finemement=20les=20elements=20que=20l'on=20veut?= =?UTF-8?q?=20rechercher,=20dans=20etre=20polu=C3=A9=20par=20les=20balises?= =?UTF-8?q?=20html.=20Notre=20json,=20pour=20la=20partie=20corps=20du=20ta?= =?UTF-8?q?bleau,=20on=20ajoute=20un=20subdivision=20:=20"html"=20:=20{=20?= =?UTF-8?q?mes=20champs},=20comme=20cela,=20on=20peut=20ajouter=20une=20no?= =?UTF-8?q?uvelle=20cle=20:=20"search"=20:=20{la=20valeur=20des=20champs?= =?UTF-8?q?=20qui=20seront=20recherch=C3=A9s=20et=20filtr=C3=A9s}.=20Cela?= =?UTF-8?q?=20alourdit=20un=20peu=20le=20html,=20et=20seulement=20son=20po?= =?UTF-8?q?ids.=20La=20partie=20html/js=20est=20toujours=20aussi=20rapide,?= =?UTF-8?q?=20et=20meme=20plus=20si=20on=20utilise=20cette=20nouvelle=20cl?= =?UTF-8?q?e.=20ATTENTION=20:=20cela=20casse=20la=20compatibilit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/gamutable.es6.js | 26 ++++++++++++++------ js/gamutable.js | 19 +++++++++------ json_gamutable.json.html | 52 +++++++++++++++++++++++++++------------- paquet.xml | 6 ++--- 4 files changed, 70 insertions(+), 33 deletions(-) diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 5fcc38b..0495776 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -37,11 +37,14 @@ function recupJson(d) { return []; } } -const orderBy = (arr, props, orders) => +const orderBy = (arr, props, orders, champ) => arr.sort((a, b) => props.reduce((acc, prop, i) => { if (acc === 0) { - let [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]]; + let [p1, p2] = + 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; @@ -102,6 +105,7 @@ let monTableau = { triOrders: [], triProps: [], selectTr: [], + champ_search: 'html', }; }, mounted() { @@ -114,7 +118,12 @@ let monTableau = { } return this.pagination( this.table.filter((ligne) => - Object.values(ligne).toString().toLowerCase().indexOf(this.search.toLowerCase()) < 0 ? false : true + Object.values(ligne[this.champ_search]) + .toString() + .toLowerCase() + .indexOf(this.search.toLowerCase()) < 0 + ? false + : true ) ); }, @@ -148,6 +157,9 @@ let monTableau = { Vue.set(this.table, i, data[0]); } else { this.table = data; + if (data[0].search) { + this.champ_search = 'search'; + } } Vue.nextTick(function () { console.timeEnd('Chargement de VueJs APRES Ajax'); @@ -182,7 +194,7 @@ let monTableau = { this.triProps.push(col); this.triOrders.push(sens); } - this.table = orderBy(this.table, this.triProps, this.triOrders); + this.table = orderBy(this.table, this.triProps, this.triOrders, this.champ_search); }, ordreActif(col, sens) { const i = this.triProps.indexOf(col); @@ -193,7 +205,7 @@ let monTableau = { } }, resetTri() { - this.table = orderBy(this.table, ['id']); + this.table = orderBy(this.table, ['id'], '', this.champ_search); this.triOrders = []; this.triProps = []; }, @@ -230,8 +242,8 @@ let monTableau = { - - + + diff --git a/js/gamutable.js b/js/gamutable.js index 8f48909..77e38d1 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -49,11 +49,11 @@ function recupJson(d) { } } -var orderBy = function orderBy(arr, props, orders) { +var orderBy = function orderBy(arr, props, orders, champ) { return arr.sort(function (a, b) { return props.reduce(function (acc, prop, i) { if (acc === 0) { - var _ref = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]], + var _ref = orders && orders[i] === 'desc' ? [b[champ][prop], a[champ][prop]] : [a[champ][prop], b[champ][prop]], _ref2 = _slicedToArray(_ref, 2), p1 = _ref2[0], p2 = _ref2[1]; // passe en lowercase les String @@ -120,7 +120,8 @@ var monTableau = { pages: [], triOrders: [], triProps: [], - selectTr: [] + selectTr: [], + champ_search: 'html' }; }, mounted: function mounted() { @@ -135,7 +136,7 @@ var monTableau = { } return this.pagination(this.table.filter(function (ligne) { - return Object.values(ligne).toString().toLowerCase().indexOf(_this.search.toLowerCase()) < 0 ? false : true; + return Object.values(ligne[_this.champ_search]).toString().toLowerCase().indexOf(_this.search.toLowerCase()) < 0 ? false : true; })); } }, @@ -176,6 +177,10 @@ var monTableau = { Vue.set(_this2.table, i, data[0]); } else { _this2.table = data; + + if (data[0].search) { + _this2.champ_search = 'search'; + } } Vue.nextTick(function () { @@ -215,7 +220,7 @@ var monTableau = { this.triOrders.push(sens); } - this.table = orderBy(this.table, this.triProps, this.triOrders); + this.table = orderBy(this.table, this.triProps, this.triOrders, this.champ_search); }, ordreActif: function ordreActif(col, sens) { var i = this.triProps.indexOf(col); @@ -227,7 +232,7 @@ var monTableau = { } }, resetTri: function resetTri() { - this.table = orderBy(this.table, ['id']); + this.table = orderBy(this.table, ['id'], '', this.champ_search); this.triOrders = []; this.triProps = []; }, @@ -243,7 +248,7 @@ var monTableau = { } } }, - template: "\n\t
\n\t\t
\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t
\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t
\n\t\t\t
{{table.length}} \xE9l\xE9ments
\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t
\n\t\t
\n\t
" + template: "\n\t
\n\t\t
\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t
\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
\n\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t
\n\t\t\t
{{table.length}} \xE9l\xE9ments
\n\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t\t
\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t
\n\t\t\t
\n\t\t
\n\t
" }; var app = new Vue({ el: '#app', diff --git a/json_gamutable.json.html b/json_gamutable.json.html index de2f3d2..4312454 100644 --- a/json_gamutable.json.html +++ b/json_gamutable.json.html @@ -35,22 +35,42 @@ })] { -"id": #ID_SOUSCRIPTION, -"modif" : [(#VAL{}|json_encode)], -"date" : [(#DATE|affdate{d/m/Y}|json_encode)], -"statut" : [(#GET{statut}|json_encode)], -"genre" : [(#GENRE|json_encode)], -"nom_souscripteur" : [(#NOM_SOUSCRIPTEUR|json_encode)], -"prenom" : [(#PRENOM|json_encode)], -"qui": [(#VAL{}|json_encode)], -"nbr" : [(#NOMBRE)], -"montant_part" : [(#MONTANT_PART)], -"montant" : [(#MONTANT)], -"prix": [(#VAL{}|json_encode)], -"type" : [(#TYPE|json_encode)], -"email" : [(#VAL{#EMAIL}|json_encode)], -"telephone" : [(#TELEPHONE|json_encode)], -"ou": [(#VAL{}|json_encode)] +"html": { + id": #ID_SOUSCRIPTION, + "modif" : [(#VAL{}|json_encode)], + "date" : [(#DATE|affdate{d/m/Y}|json_encode)], + "statut" : [(#GET{statut}|json_encode)], + "genre" : [(#GENRE|json_encode)], + "nom_souscripteur" : [(#NOM_SOUSCRIPTEUR|json_encode)], + "prenom" : [(#PRENOM|json_encode)], + "qui": [(#VAL{}|json_encode)], + "nbr" : [(#NOMBRE)], + "montant_part" : [(#MONTANT_PART)], + "montant" : [(#MONTANT)], + "prix": [(#VAL{}|json_encode)], + "type" : [(#TYPE|json_encode)], + "email" : [(#VAL{#EMAIL}|json_encode)], + "telephone" : [(#TELEPHONE|json_encode)], + "ou": [(#VAL{}|json_encode)] +}, +search: { + id": #ID_SOUSCRIPTION, + "modif" : "", + "date" : [(#DATE|affdate{d/m/Y}|json_encode)], + "statut" : [(#GET{statut}|json_encode)], + "genre" : [(#GENRE|json_encode)], + "nom_souscripteur" : [(#NOM_SOUSCRIPTEUR|json_encode)], + "prenom" : [(#PRENOM|json_encode)], + "qui": "", + "nbr" : [(#NOMBRE)], + "montant_part" : [(#MONTANT_PART)], + "montant" : [(#MONTANT)], + "prix": "", + "type" : [(#TYPE|json_encode)], + "email" : [(#EMAIL|json_encode)], + "telephone" : [(#TELEPHONE|json_encode)], + "ou": "" +} } ] diff --git a/paquet.xml b/paquet.xml index fafab3c..37ec1d3 100644 --- a/paquet.xml +++ b/paquet.xml @@ -1,7 +1,7 @@ GamuTable - + tofulm GNU/GPL - +