diff --git a/js/gamutable.es6.js b/js/gamutable.es6.js index 43c20a3..d623500 100644 --- a/js/gamutable.es6.js +++ b/js/gamutable.es6.js @@ -22,6 +22,16 @@ function recupJson(d) { return []; } } +const orderBy = (arr, props, orders) => + arr.sort((a, b) => + props.reduce((acc, prop, i) => { + if (acc === 0) { + const [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]]; + acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; + } + return acc; + }, 0) + ); console.time('Chargement de VueJS AVANT Ajax'); console.time('Chargement de VueJs APRES Ajax'); Vue.nextTick(function() { @@ -132,16 +142,6 @@ let monTableau = { this.triProps.push(col); this.triOrders.push(sens); } - const orderBy = (arr, props, orders) => - arr.sort((a, b) => - props.reduce((acc, prop, i) => { - if (acc === 0) { - const [p1, p2] = orders && orders[i] === 'desc' ? [b[prop], a[prop]] : [a[prop], b[prop]]; - acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; - } - return acc; - }, 0) - ); this.table = orderBy(this.table, this.triProps, this.triOrders); }, ordreActif(col, sens) { @@ -151,6 +151,11 @@ let monTableau = { return 'active'; } } + }, + resetTri() { + this.table = orderBy(this.table, ['id']); + this.triOrders = []; + this.triProps = []; } }, template: ` @@ -162,6 +167,7 @@ let monTableau = { + diff --git a/js/gamutable.js b/js/gamutable.js index d738633..c9c0fee 100644 --- a/js/gamutable.js +++ b/js/gamutable.js @@ -34,6 +34,23 @@ function recupJson(d) { } } +var orderBy = function orderBy(arr, props, orders) { + 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]], + _ref2 = _slicedToArray(_ref, 2), + p1 = _ref2[0], + p2 = _ref2[1]; + + acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; + } + + return acc; + }, 0); + }); +}; + console.time('Chargement de VueJS AVANT Ajax'); console.time('Chargement de VueJs APRES Ajax'); Vue.nextTick(function () { @@ -151,23 +168,6 @@ var monTableau = { this.triOrders.push(sens); } - var orderBy = function orderBy(arr, props, orders) { - 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]], - _ref2 = _slicedToArray(_ref, 2), - p1 = _ref2[0], - p2 = _ref2[1]; - - acc = p1 > p2 ? 1 : p1 < p2 ? -1 : 0; - } - - return acc; - }, 0); - }); - }; - this.table = orderBy(this.table, this.triProps, this.triOrders); }, ordreActif: function ordreActif(col, sens) { @@ -178,9 +178,14 @@ var monTableau = { return 'active'; } } + }, + resetTri: function resetTri() { + this.table = orderBy(this.table, ['id']); + this.triOrders = []; + this.triProps = []; } }, - template: "\n\t
\n\t\t

{{ message }}

\n\t\t
\n\t\t\t
\n\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\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\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\t\t\t\t{{head}}\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\n\t\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\t{{td}}\n\t\t\t\t\t\t
\n\t\t\t
\n\t\t\t\t
{{table.length}} \xE9l\xE9ments
\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

{{ message }}

\n\t\t
\n\t\t\t
\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t
\n\t\t\t\n\t\t\t\t\n\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