From 63ca733307d54b4fb80d4694580ab42a9efd2809 Mon Sep 17 00:00:00 2001 From: D J Date: Wed, 4 Sep 2019 10:05:43 -0500 Subject: [PATCH] Update ColumnHider extension to support ColumnSet This is a customization I added to version 0.3.19 to allow the ColumnHider to work with grids that use ColumnSet. --- extensions/ColumnHider.js | 60 ++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/extensions/ColumnHider.js b/extensions/ColumnHider.js index 1d941625c..241e9c4d8 100644 --- a/extensions/ColumnHider.js +++ b/extensions/ColumnHider.js @@ -1,11 +1,12 @@ define([ 'dojo/_base/declare', + 'dojo/_base/array', 'dojo/dom-construct', 'dojo/has', 'dojo/on', '../util/misc', 'dojo/i18n!./nls/columnHider' -], function (declare, domConstruct, has, listen, miscUtil, i18n) { +], function (declare, array, domConstruct, has, listen, miscUtil, i18n) { /* * Column Hider plugin for dgrid * Originally contributed by TRT 2011-09-28 @@ -16,7 +17,7 @@ define([ * 1. Menu placement is entirely based on CSS definitions. * 2. If you want columns initially hidden, you must add "hidden: true" to your * column definition. - * 3. This implementation does NOT support ColumnSet, and has not been tested + * 3. This implementation DOES support ColumnSet, but has not been tested * with multi-subrow records. * 4. Column show/hide is controlled via straight up HTML checkboxes. If you * are looking for something more fancy, you'll probably need to use this @@ -62,25 +63,44 @@ define([ _renderHiderMenuEntries: function () { // summary: - // Iterates over subRows for the sake of adding items to the + // Iterates over subRows or columnSets for the sake of adding items to the // column hider menu. - - var subRows = this.subRows, - first = true, - srLength, cLength, sr, c; - - delete this._columnHiderFirstCheckbox; - - for (sr = 0, srLength = subRows.length; sr < srLength; sr++) { - for (c = 0, cLength = subRows[sr].length; c < cLength; c++) { - this._renderHiderMenuEntry(subRows[sr][c]); - if (first) { - first = false; - this._columnHiderFirstCheckbox = - this._columnHiderCheckboxes[subRows[sr][c].id]; - } - } - } + + if (this.subRows && this.subRows.length) { + var subRows = this.subRows, + first = true, + srLength, cLength, sr, c; + + delete this._columnHiderFirstCheckbox; + + for (sr = 0, srLength = subRows.length; sr < srLength; sr++) { + for (c = 0, cLength = subRows[sr].length; c < cLength; c++) { + this._renderHiderMenuEntry(subRows[sr][c]); + if (first) { + first = false; + this._columnHiderFirstCheckbox = + this._columnHiderCheckboxes[subRows[sr][c].id]; + } + } + } + } + else if (this.columnSets && this.columnSets.length) { + // Loop through each this.columnSets + array.forEach(this.columnSets, function (columnSet) { + // Loop through each columnSet + array.forEach(columnSet, function (columnSetColumns) { + // Loop through each columnSetColumns + array.forEach(columnSetColumns, function (column) { + // Render a checkbox for each column + this._renderHiderMenuEntry(column); + // Keep track of the first checkbox + this._columnHiderFirstCheckbox = + this._columnHiderFirstCheckbox || + this._columnHiderCheckboxes[column.id]; + }, this); + }, this); + }, this); + } }, _renderHiderMenuEntry: function (col) {