all files / grid/actions/ show-hide.js

93.33% Statements 42/45
85.71% Branches 12/14
100% Functions 12/12
93.33% Lines 42/45
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69   335×   4768× 4768× 4768× 4768× 4769×   4768×   4757× 4757× 4757× 4757× 4757×   4757×   9525× 9525× 6351×     3174×   9525×   9525× 9525× 9526× 47630× 9526×   38104×     9525×   11106×             11106× 11106×   11106× 11106×            
define(["require", "exports", "@syncfusion/ej2-base", "../base/util", "../base/constant"], function (require, exports, ej2_base_1, util_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ShowHide = (function () {
        function ShowHide(parent) {
            this.parent = parent;
        }
        ShowHide.prototype.show = function (columnName, showBy) {
            var keys = this.getToggleFields(columnName);
            var columns = this.getColumns(keys, showBy);
            this.parent.notify(events.tooltipDestroy, { module: 'edit' });
            columns.forEach(function (value) {
                value.visible = true;
            });
            this.setVisible(columns);
        };
        ShowHide.prototype.hide = function (columnName, hideBy) {
            var keys = this.getToggleFields(columnName);
            var columns = this.getColumns(keys, hideBy);
            this.parent.notify(events.tooltipDestroy, { module: 'edit' });
            columns.forEach(function (value) {
                value.visible = false;
            });
            this.setVisible(columns);
        };
        ShowHide.prototype.getToggleFields = function (key) {
            var finalized = [];
            if (typeof key === 'string') {
                finalized = [key];
            }
            else {
                finalized = key;
            }
            return finalized;
        };
        ShowHide.prototype.getColumns = function (keys, getKeyBy) {
            var _this = this;
            var columns = util_1.iterateArrayOrObject(keys, function (key, index) {
                return util_1.iterateArrayOrObject(_this.parent.getColumns(), function (item, index) {
                    if (item[getKeyBy] === key) {
                        return item;
                    }
                    return undefined;
                })[0];
            });
            return columns;
        };
        ShowHide.prototype.setVisible = function (columns) {
            Iif (util_1.isActionPrevent(this.parent)) {
                this.parent.notify(events.preventBatch, {
                    instance: this, handler: this.setVisible,
                    arg1: columns
                });
                return;
            }
            columns = ej2_base_1.isNullOrUndefined(columns) ? this.parent.getColumns() : columns;
            if (this.parent.allowSelection && this.parent.getSelectedRecords().length) {
                this.parent.clearSelection();
            }
            this.parent.notify(events.columnVisibilityChanged, columns);
            Iif (this.parent.columnQueryMode !== 'All') {
                this.parent.refresh();
            }
        };
        return ShowHide;
    }());
    exports.ShowHide = ShowHide;
});