Skip to content

Commit

Permalink
Update ColumnHider extension to support ColumnSet
Browse files Browse the repository at this point in the history
This is a customization I added to version 0.3.19 to allow the ColumnHider to work with grids that use ColumnSet.
  • Loading branch information
jacobsdc authored and msssk committed Apr 8, 2020
1 parent 488aae2 commit 63ca733
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions extensions/ColumnHider.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 63ca733

Please sign in to comment.