Skip to content

Commit

Permalink
ColumnHider: add test grid and clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
msssk committed Apr 8, 2020
1 parent 63ca733 commit 06d9d10
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 40 deletions.
71 changes: 33 additions & 38 deletions extensions/ColumnHider.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
define([
'dojo/_base/array',
'dojo/_base/declare',
'dojo/_base/array',
'dojo/dom-construct',
'dojo/has',
'dojo/on',
'../util/misc',
'dojo/i18n!./nls/columnHider'
], function (declare, array, domConstruct, has, listen, miscUtil, i18n) {
], function (arrayUtil, declare, domConstruct, has, listen, miscUtil, i18n) {
/*
* Column Hider plugin for dgrid
* Originally contributed by TRT 2011-09-28
Expand Down Expand Up @@ -65,42 +65,37 @@ define([
// summary:
// Iterates over subRows or columnSets for the sake of adding items to the
// column hider menu.

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);
}

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) {
arrayUtil.forEach(this.columnSets, function (columnSet) {
arrayUtil.forEach(columnSet, function (columnSetColumns) {
arrayUtil.forEach(columnSetColumns, function (column) {
this._renderHiderMenuEntry(column);
this._columnHiderFirstCheckbox =
this._columnHiderFirstCheckbox ||
this._columnHiderCheckboxes[column.id];
}, this);
}, this);
}, this);
}
},

_renderHiderMenuEntry: function (col) {
Expand Down
31 changes: 29 additions & 2 deletions test/extensions/ColumnHider.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
// Functions defined within require callback
var getColumns, getAltColumns, createGrid, destroyGrid;

require(["dojo/_base/lang", "dojo/_base/declare", "dojo/dom-construct",
require(["dojo/_base/lang", "dojo/_base/declare", "dojo/dom-construct", "dgrid/ColumnSet",
"dgrid/OnDemandGrid", "dgrid/Keyboard", "dgrid/Selection",
"dgrid/extensions/ColumnHider", "dgrid/extensions/ColumnResizer", "dgrid/extensions/ColumnReorder",
"dgrid/test/data/testStore", "dojo/domReady!"],
function(lang, declare, domConstruct, Grid, Keyboard, Selection, ColumnHider, ColumnResizer, ColumnReorder, testStore){
function(lang, declare, domConstruct, ColumnSet, Grid, Keyboard, Selection, ColumnHider, ColumnResizer, ColumnReorder, testStore){
var columns = {
col1: "Column 1Column1Column 1 Column 1",
col2: { label: "Column2 (unhidable)", sortable: false, unhidable: true },
Expand Down Expand Up @@ -106,6 +106,30 @@
collection: testStore,
columns: lang.clone(columns)
}, "gridreorder");

window.gridColumnSet = new (declare([Grid, Selection, ColumnHider, ColumnSet]))({
collection: testStore,
columnSets: [
[
[
{ field: "col1", label: "Column 1" },
{ field: "col2", label: "Column 2" }
],
[
{ field: "col3", label: "Column 3", colSpan: 2 }
]
],
[
[
{ field: "col1", label: "Column 1", rowSpan: 2 },
{ field: "col4", label: "Column 4" }
],
[
{ field: "col5", label: "Column 5" }
]
]
]
}, "gridColumnSet");
});
</script>
</head>
Expand All @@ -121,5 +145,8 @@ <h2>Another grid w/ ColumnHider and ColumnResizer</h2>
<div id="gridresize"></div>
<h2>Another grid w/ ColumnHider and ColumnReorder</h2>
<div id="gridreorder"></div>

<h2>Grid with ColumnHider and ColumnSet</h2>
<div id="gridColumnSet"></div>
</body>
</html>

0 comments on commit 06d9d10

Please sign in to comment.