diff --git a/README.md b/README.md index e06f4e5..844614b 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Choisir entre la version minifiée de vuejs (sans le debug) ou la version de dev "email":"toto" } ``` -- On peut ajouter des tris par colonne soit avec un select soit avec un input +- On peut ajouter des filtres par colonne soit avec un select soit avec un input ```json "filtreCol" : { "statut" : "select", @@ -61,6 +61,12 @@ Choisir entre la version minifiée de vuejs (sans le debug) ou la version de dev "prenom": "input" } ``` +- On peut ajouter des ordre de tri par colonne : `asc` ou `desc` +```json +"ordreCol" : { + "nom" : "desc" +} +``` ## Utiliser les actions : diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 468d1c3..f0c9df2 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -221,6 +221,7 @@ let monTableau = { header: [], crayons: [], classes: [], + ordreCol: [], filtreCol: [], filtreColExist: false, filtreColType: [], @@ -257,6 +258,13 @@ let monTableau = { this.vuebloc = data; }); } + setTimeout(() => { + if (this.ordreCol) { + Object.entries(this.ordreCol).forEach(([col, sens]) => { + this.tri(col, sens); + }); + } + }, 500); }, computed: { filtreColVal_visible: function () { @@ -367,6 +375,7 @@ let monTableau = { crayons: this.crayons, classes: this.classes, filtreCol: this.filtreColType, + ordreCol: this.ordreCol, }; localStorage.setItem('header_' + this.nameLocalStorage, JSON.stringify($header)); @@ -446,6 +455,9 @@ let monTableau = { if (config.classes !== undefined) { this.classes = config.classes; } + if (config.ordreCol !== undefined) { + this.ordreCol = config.ordreCol; + } let filtreCol = []; if (config.filtreCol !== undefined) { filtreCol = config.filtreCol; @@ -498,6 +510,9 @@ let monTableau = { if (config.classes !== undefined) { this.classes = config.classes; } + if (config.ordreCol !== undefined) { + this.ordreCol = config.ordreCol; + } if (parseInt(id) > 0) { if (data.length > 0) { let i = trouver_index(this.table, id); diff --git a/js/gamutable.js b/js/gamutable.js index 3a11172..f84bab2 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -273,6 +273,7 @@ var monTableau = { header: [], crayons: [], classes: [], + ordreCol: [], filtreCol: [], filtreColExist: false, filtreColType: [], @@ -312,6 +313,18 @@ var monTableau = { _this.vuebloc = data; }); } + + setTimeout(function () { + if (_this.ordreCol) { + Object.entries(_this.ordreCol).forEach(function (_ref3) { + var _ref4 = _slicedToArray(_ref3, 2), + col = _ref4[0], + sens = _ref4[1]; + + _this.tri(col, sens); + }); + } + }, 500); }, computed: { filtreColVal_visible: function filtreColVal_visible() { @@ -410,7 +423,8 @@ var monTableau = { header: this.header, crayons: this.crayons, classes: this.classes, - filtreCol: this.filtreColType + filtreCol: this.filtreColType, + ordreCol: this.ordreCol }; localStorage.setItem('header_' + this.nameLocalStorage, JSON.stringify($header)); $table = this.table; @@ -447,10 +461,10 @@ var monTableau = { var ObfiltreSelect = []; if (this.filtreColSelected) { - Object.entries(this.filtreColSelected).forEach(function (_ref3) { - var _ref4 = _slicedToArray(_ref3, 2), - champ = _ref4[0], - valeurs = _ref4[1]; + Object.entries(this.filtreColSelected).forEach(function (_ref5) { + var _ref6 = _slicedToArray(_ref5, 2), + champ = _ref6[0], + valeurs = _ref6[1]; if (!Array.isArray(valeurs)) { valeurs = [valeurs]; @@ -512,6 +526,10 @@ var monTableau = { this.classes = config.classes; } + if (config.ordreCol !== undefined) { + this.ordreCol = config.ordreCol; + } + var filtreCol = []; if (config.filtreCol !== undefined) { @@ -573,6 +591,10 @@ var monTableau = { _this4.classes = config.classes; } + if (config.ordreCol !== undefined) { + _this4.ordreCol = config.ordreCol; + } + if (parseInt(id) > 0) { if (data.length > 0) { var i = trouver_index(_this4.table, id); diff --git a/json_gamutable.json.html b/json_gamutable.json.html index 5a33dc6..9fd23fe 100644 --- a/json_gamutable.json.html +++ b/json_gamutable.json.html @@ -11,6 +11,9 @@ "crayons":{ "titre" : "article" }, +"ordreCol" : { + "titre" : "desc", +} "filtreCol" : { "statut" : "select", "titre": "input"