diff --git a/dist/tablefilter/tf-1.js b/dist/tablefilter/tf-1.js index 13335d51..c90797fa 100644 --- a/dist/tablefilter/tf-1.js +++ b/dist/tablefilter/tf-1.js @@ -1121,19 +1121,19 @@ webpackJsonp([1],{ if (!this.manager) { return; } - this.buildBtn(); - this.buildManager(); - - this.initialized = true; this.emitter.on(['hide-column'], function (tf, colIndex) { return _this.hideCol(colIndex); }); + + this.buildBtn(); + this.buildManager(); + + this.initialized = true; this.emitter.emit('columns-visibility-initialized', tf, this); // Hide columns at start at very end of initialization - // TODO: re-evaluate this as conceptually wrong - this.hideAtStart(); + this._hideAtStart(); }; /** @@ -1294,17 +1294,6 @@ webpackJsonp([1],{ this.btnEl.parentNode.insertBefore(container, this.btnEl); this.contEl = container; - - // if (this.atStart) { - // let a = this.atStart; - // for (let k = 0; k < a.length; k++) { - // // let itm = Dom.id('col_' + a[k] + '_' + tf.id); - // // if (itm) { - // // itm.click(); - // // } - // this.hideCol(a[k]); - // } - // } }; /** @@ -1463,21 +1452,6 @@ webpackJsonp([1],{ return this.hiddenCols; }; - /** - * Hide columns at start - */ - - - ColsVisibility.prototype.hideAtStart = function hideAtStart() { - if (!this.atStart) { - return; - } - var a = this.atStart; - for (var k = 0; k < a.length; k++) { - this.hideCol(a[k]); - } - }; - /** * Remove the columns manager */ @@ -1538,6 +1512,17 @@ webpackJsonp([1],{ } }; + ColsVisibility.prototype._hideAtStart = function _hideAtStart() { + var _this5 = this; + + if (!this.atStart) { + return; + } + this.atStart.forEach(function (colIdx) { + _this5.hideCol(colIdx); + }); + }; + return ColsVisibility; }(); diff --git a/src/extensions/colsVisibility/colsVisibility.js b/src/extensions/colsVisibility/colsVisibility.js index 350b5016..e35ffdc4 100644 --- a/src/extensions/colsVisibility/colsVisibility.js +++ b/src/extensions/colsVisibility/colsVisibility.js @@ -174,18 +174,18 @@ export default class ColsVisibility { if (!this.manager) { return; } + + this.emitter.on(['hide-column'], + (tf, colIndex) => this.hideCol(colIndex)); + this.buildBtn(); this.buildManager(); this.initialized = true; - - this.emitter.on(['hide-column'], - (tf, colIndex) => this.hideCol(colIndex)); this.emitter.emit('columns-visibility-initialized', tf, this); // Hide columns at start at very end of initialization - // TODO: re-evaluate this as conceptually wrong - this.hideAtStart(); + this._hideAtStart(); } /** @@ -329,17 +329,6 @@ export default class ColsVisibility { this.btnEl.parentNode.insertBefore(container, this.btnEl); this.contEl = container; - - // if (this.atStart) { - // let a = this.atStart; - // for (let k = 0; k < a.length; k++) { - // // let itm = Dom.id('col_' + a[k] + '_' + tf.id); - // // if (itm) { - // // itm.click(); - // // } - // this.hideCol(a[k]); - // } - // } } /** @@ -490,19 +479,6 @@ export default class ColsVisibility { return this.hiddenCols; } - /** - * Hide columns at start - */ - hideAtStart() { - if (!this.atStart) { - return; - } - let a = this.atStart; - for (let k = 0; k < a.length; k++) { - this.hideCol(a[k]); - } - } - /** * Remove the columns manager */ @@ -558,4 +534,12 @@ export default class ColsVisibility { } } + _hideAtStart() { + if (!this.atStart) { + return; + } + this.atStart.forEach((colIdx) => { + this.hideCol(colIdx); + }); + } } diff --git a/test/test-state.js b/test/test-state.js index bc2d4afd..69614414 100644 --- a/test/test-state.js +++ b/test/test-state.js @@ -119,6 +119,20 @@ test('Can update sort', function() { { 'sort': { 'descending': true } }, 'Sort updated'); }); +test('Can update columns visibility', function() { + // setup + state.persistColsVisibility = true; + state.state = {}; + + // act + state.updateColsVisibility([0, 2]); + state.persistColsVisibility = false; + + // assert + deepEqual(state.state.col_0.hidden, true, 'Column 0 visibility updated'); + deepEqual(state.state.col_2.hidden, true, 'Column 2 visibility updated'); +}); + module('Tear-down'); test('Can destroy TF', function() { // setup