From 56372115471e04a09a7f28e94b46370595f007a2 Mon Sep 17 00:00:00 2001 From: tofulm Date: Mon, 9 Nov 2020 15:15:40 +0100 Subject: [PATCH] filtrage par col, petit bug dans la deslection --- js/gamutable.es6.js | 73 +++++++++++++++++++++++++++++++++++++++------ js/gamutable.js | 55 ++++++++++++++++++++++++++++++---- 2 files changed, 114 insertions(+), 14 deletions(-) diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 6d6bdd8..c240e54 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -186,6 +186,10 @@ let monTableau = { header: [], crayons: [], classes: [], + filtreCol: [], + filtreColSelected: [], + filtreColModif: 0, + filtreColVal: {}, search: '', page: 1, parPage: sessionStorage.getItem('nbItems') ? sessionStorage.getItem('nbItems') : this.tparpage[0], @@ -213,19 +217,35 @@ let monTableau = { }, computed: { tableau: function () { + console.log('modif ', this.filtreColModif); + console.log(this.filtreColSelected); this.setPages(); - if (!this.search) { + //if (!this.search) { + if (!this.search && !this.filtreColModif) { return this.pagination(this.table); } return this.pagination( - this.table.filter((ligne) => - Object.values(ligne[this.champ_search]) - .toString() - .toLowerCase() - .indexOf(this.search.toLowerCase()) < 0 - ? false - : true - ) + this.table.filter((ligne) => { + let rsearch = + Object.values(ligne[this.champ_search]) + .toString() + .toLowerCase() + .indexOf(this.search.toLowerCase()) < 0 + ? false + : true; + if (!rsearch) { + return false; + } + Object.keys(this.filtreColSelected).forEach((colName) => { + let colValue = this.filtreColSelected[colName]; + if (colValue) { + if (ligne.html[colName] !== colValue) { + rsearch = false; + } + } + }); + return rsearch; + }) ); }, }, @@ -246,6 +266,7 @@ let monTableau = { header: this.header, crayons: this.crayons, classes: this.classes, + filtreCol: this.filtreCol, }, ], ...this.table, @@ -254,6 +275,12 @@ let monTableau = { }, }, methods: { + selectValCol(val) { + this.filtreColModif++; + //} else { + //this.filtreColModif = false; + //} + }, calculer_nameLocalStorage() { if (this.apiuri) { return this.apiuri.match(/.*page=(.*)/)[1]; @@ -308,6 +335,20 @@ let monTableau = { this.champ_search = 'search'; } } + if (config.filtreCol !== undefined) { + this.filtreCol = config.filtreCol; + //this.filtreColSelected = 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; + }); + } Vue.nextTick(() => { this.chargement = false; if ($_id > 0) { @@ -410,6 +451,7 @@ let monTableau = { template: `
+
{{tableau.length}} / {{table.length}} éléments
@@ -470,6 +512,19 @@ let monTableau = { + + +
+ +
+ + diff --git a/js/gamutable.js b/js/gamutable.js index 171caac..ef5ee4c 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -235,6 +235,10 @@ var monTableau = { header: [], crayons: [], classes: [], + filtreCol: [], + filtreColSelected: [], + filtreColModif: 0, + filtreColVal: {}, search: '', page: 1, parPage: sessionStorage.getItem('nbItems') ? sessionStorage.getItem('nbItems') : this.tparpage[0], @@ -267,14 +271,31 @@ var monTableau = { tableau: function tableau() { var _this2 = this; - this.setPages(); + console.log('modif ', this.filtreColModif); + console.log(this.filtreColSelected); + this.setPages(); //if (!this.search) { - if (!this.search) { + if (!this.search && !this.filtreColModif) { return this.pagination(this.table); } return this.pagination(this.table.filter(function (ligne) { - return Object.values(ligne[_this2.champ_search]).toString().toLowerCase().indexOf(_this2.search.toLowerCase()) < 0 ? false : true; + var rsearch = Object.values(ligne[_this2.champ_search]).toString().toLowerCase().indexOf(_this2.search.toLowerCase()) < 0 ? false : true; + + if (!rsearch) { + return false; + } + + Object.keys(_this2.filtreColSelected).forEach(function (colName) { + var colValue = _this2.filtreColSelected[colName]; + + if (colValue) { + if (ligne.html[colName] !== colValue) { + rsearch = false; + } + } + }); + return rsearch; })); } }, @@ -293,12 +314,18 @@ var monTableau = { $table = [{ header: this.header, crayons: this.crayons, - classes: this.classes + classes: this.classes, + filtreCol: this.filtreCol }].concat(_toConsumableArray(this.table)); localStorage.setItem(this.nameLocalStorage, JSON.stringify($table)); } }, methods: { + selectValCol: function selectValCol(val) { + this.filtreColModif++; //} else { + //this.filtreColModif = false; + //} + }, calculer_nameLocalStorage: function calculer_nameLocalStorage() { if (this.apiuri) { return this.apiuri.match(/.*page=(.*)/)[1]; @@ -370,6 +397,24 @@ var monTableau = { } } + if (config.filtreCol !== undefined) { + _this3.filtreCol = config.filtreCol; //this.filtreColSelected = config.filtreCol; + + _this3.filtreCol.forEach(function (col) { + var Tval = ['']; + + _this3.table.forEach(function (t) { + var valCol = t.html[col]; + + if (Tval.indexOf(valCol) === -1) { + Tval.push(valCol); + } + }); + + _this3.filtreColVal[col] = Tval; + }); + } + Vue.nextTick(function () { _this3.chargement = false; @@ -488,7 +533,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\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
{{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
{{tableau.length}} / {{table.length}} \xE9l\xE9ments
\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\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\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
" }; var gamuTable = { components: {