From 299e86312083a6f786b424d16dc91bf4b837ae59 Mon Sep 17 00:00:00 2001 From: tofulm Date: Mon, 25 Jan 2021 20:14:43 +0100 Subject: [PATCH] ajout de selecteur input, todo : maj du readme --- js/gamutable.es6.js | 97 +++++++++++++++++++++++++++++---------------- js/gamutable.js | 89 +++++++++++++++++++++-------------------- 2 files changed, 107 insertions(+), 79 deletions(-) diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 67539a2..2c2b044 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -190,7 +190,9 @@ let monTableau = { crayons: [], classes: [], filtreCol: [], - filtreColSelected: { gestionnaire: [] }, + filtreColExist: false, + filtreColType: [], + filtreColSelected: {}, filtreColModif: 0, filtreColVal: {}, search: '', @@ -238,26 +240,43 @@ let monTableau = { if (!rsearch) { return false; } + Object.keys(this.filtreColSelected).forEach((colName) => { - console.log('coucou'); if (rsearch) { let colValue = this.filtreColSelected[colName]; - if (!Array.isArray(colValue)) { - colValue = [colValue]; - } - let TcolValue = []; - colValue.forEach((s) => { - if (Number.isInteger(s)) { - TcolValue.push(s); + if (colValue !== null) { + if (!Array.isArray(colValue)) { + colValue = [colValue]; } - if (s.length > 0) { - TcolValue.push(s); - } - }); + let TcolValue = []; + colValue.forEach((s) => { + if (Number.isInteger(s)) { + TcolValue.push(s); + } + if (s.length > 0) { + TcolValue.push(s.toLowerCase()); + } + }); - if (TcolValue.length) { - if (TcolValue.indexOf(ligne.html[colName]) === -1) { - rsearch = false; + if (TcolValue.length) { + if (this.filtreColType[colName] === 'select') { + if ( + TcolValue.toString().indexOf( + ligne[this.champ_search][colName].toString().toLowerCase() + ) === -1 + ) { + rsearch = false; + } + } else { + if ( + ligne[this.champ_search][colName] + .toString() + .toLowerCase() + .indexOf(TcolValue.toString()) === -1 + ) { + rsearch = false; + } + } } } } @@ -313,7 +332,6 @@ let monTableau = { }, methods: { selectValCol() { - //console.log(this.filtreColSelected); this.filtreColModif++; }, calculer_nameLocalStorage() { @@ -342,20 +360,20 @@ let monTableau = { if (config.classes !== undefined) { this.classes = config.classes; } - if (config.filtreCol !== undefined) { - this.filtreCol = config.filtreCol; - this.filtreCol.forEach((col) => { - let Tval = ['']; - this.table.forEach((t) => { - let valCol = t.html[col]; - if (Tval.indexOf(valCol) === -1) { - Tval.push(valCol); - } - }); - this.filtreColVal[col] = Tval; - this.filtreColSelected[col] = []; - }); - } + // if (config.filtreCol !== undefined) { + // this.filtreCol = config.filtreCol; + // this.filtreCol.forEach((col) => { + // let Tval = ['']; + // this.table.forEach((t) => { + // let valCol = t.html[col]; + // if (Tval.indexOf(valCol) === -1) { + // Tval.push(valCol); + // } + // }); + // this.filtreColVal[col] = Tval; + // this.filtreColSelected[col] = []; + // }); + // } this.table = data; if (data.length && data[0].search) { this.champ_search = 'search'; @@ -389,8 +407,8 @@ let monTableau = { } } if (config.filtreCol !== undefined) { - this.filtreCol = config.filtreCol; - this.filtreCol.forEach((col) => { + this.filtreColType = config.filtreCol; + Object.keys(this.filtreColType).forEach((col) => { let Tval = ['']; this.table.forEach((t) => { let valCol = t.html[col]; @@ -398,6 +416,7 @@ let monTableau = { Tval.push(valCol); } }); + this.filtreCol.push(col); this.filtreColVal[col] = Tval; this.filtreColSelected[col] = []; }); @@ -568,6 +587,7 @@ let monTableau = {
+ +
@@ -615,8 +644,6 @@ const gamuTable = { }, }; -console.log(window.VueNextSelect); - let app = Vue.createApp(gamuTable); app.component('vue-select', window.VueNextSelect); app.mount('#app'); diff --git a/js/gamutable.js b/js/gamutable.js index 910241c..d648bc0 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -239,9 +239,9 @@ var monTableau = { crayons: [], classes: [], filtreCol: [], - filtreColSelected: { - gestionnaire: [] - }, + filtreColExist: false, + filtreColType: [], + filtreColSelected: {}, filtreColModif: 0, filtreColVal: {}, search: '', @@ -292,29 +292,35 @@ var monTableau = { } Object.keys(_this2.filtreColSelected).forEach(function (colName) { - console.log('coucou'); - if (rsearch) { var colValue = _this2.filtreColSelected[colName]; - if (!Array.isArray(colValue)) { - colValue = [colValue]; - } - - var TcolValue = []; - colValue.forEach(function (s) { - if (Number.isInteger(s)) { - TcolValue.push(s); + if (colValue !== null) { + if (!Array.isArray(colValue)) { + colValue = [colValue]; } - if (s.length > 0) { - TcolValue.push(s); - } - }); + var TcolValue = []; + colValue.forEach(function (s) { + if (Number.isInteger(s)) { + TcolValue.push(s); + } - if (TcolValue.length) { - if (TcolValue.indexOf(ligne.html[colName]) === -1) { - rsearch = false; + if (s.length > 0) { + TcolValue.push(s.toLowerCase()); + } + }); + + if (TcolValue.length) { + if (_this2.filtreColType[colName] === 'select') { + if (TcolValue.toString().indexOf(ligne[_this2.champ_search][colName].toString().toLowerCase()) === -1) { + rsearch = false; + } + } else { + if (ligne[_this2.champ_search][colName].toString().toLowerCase().indexOf(TcolValue.toString()) === -1) { + rsearch = false; + } + } } } } @@ -370,7 +376,6 @@ var monTableau = { }, methods: { selectValCol: function selectValCol() { - //console.log(this.filtreColSelected); this.filtreColModif++; }, calculer_nameLocalStorage: function calculer_nameLocalStorage() { @@ -406,25 +411,21 @@ var monTableau = { if (config.classes !== undefined) { this.classes = config.classes; - } + } // if (config.filtreCol !== undefined) { + // this.filtreCol = config.filtreCol; + // this.filtreCol.forEach((col) => { + // let Tval = ['']; + // this.table.forEach((t) => { + // let valCol = t.html[col]; + // if (Tval.indexOf(valCol) === -1) { + // Tval.push(valCol); + // } + // }); + // this.filtreColVal[col] = Tval; + // this.filtreColSelected[col] = []; + // }); + // } - if (config.filtreCol !== undefined) { - this.filtreCol = config.filtreCol; - this.filtreCol.forEach(function (col) { - var Tval = ['']; - - _this4.table.forEach(function (t) { - var valCol = t.html[col]; - - if (Tval.indexOf(valCol) === -1) { - Tval.push(valCol); - } - }); - - _this4.filtreColVal[col] = Tval; - _this4.filtreColSelected[col] = []; - }); - } this.table = data; @@ -468,9 +469,8 @@ var monTableau = { } if (config.filtreCol !== undefined) { - _this4.filtreCol = config.filtreCol; - - _this4.filtreCol.forEach(function (col) { + _this4.filtreColType = config.filtreCol; + Object.keys(_this4.filtreColType).forEach(function (col) { var Tval = ['']; _this4.table.forEach(function (t) { @@ -481,6 +481,8 @@ var monTableau = { } }); + _this4.filtreCol.push(col); + _this4.filtreColVal[col] = Tval; _this4.filtreColSelected[col] = []; }); @@ -604,7 +606,7 @@ var monTableau = { this.quelleVue = vue; } }, - template: "\n\t
\n\t\t
\n\t\t\t\n\t\t\t\n\n\t\t\t\n\n\t\t\t\n\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tMise \xE0 jour de la base de donn\xE9e\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
\n\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\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\t\n\t\t\t\t\t\t\t\n\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\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
{{tableau.length}} / {{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\n\t\t\t\n\n\t\t\t\n\n\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\tMise \xE0 jour de la base de donn\xE9e\n\t\t\t\t\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t
\n\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\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\t\n\t\t\t\t\t\t\t\n\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\t
\n\t\t\t\t\t\t\t\n\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
{{tableau.length}} / {{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 gamuTable = { components: { @@ -616,7 +618,6 @@ var gamuTable = { } } }; -console.log(window.VueNextSelect); var app = Vue.createApp(gamuTable); app.component('vue-select', window.VueNextSelect); app.mount('#app'); \ No newline at end of file