slickgrid 2.4.5 → 2.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ff99f00455831f57630e3801f3f876efbb7b7ee
4
- data.tar.gz: 1ffe1c0bfad0c20f25f18d0e9ecf99adacaf3759
3
+ metadata.gz: c41868db700a74173821c903442e06312d69d5c7
4
+ data.tar.gz: 6e457a267a195e537b30ada036b56897319b38e6
5
5
  SHA512:
6
- metadata.gz: cde211d3104b85d486afa9dab9260787529aff8ab7514c2ea1e39b8eb048b30a16732964b3ee8c37e64bcffd8c6acd0e96f8fe7ef86cb3e29dac22ed6fb88b30
7
- data.tar.gz: d6f02024be59b054c070c4e567be992333c26f73b72a6851de8d77844570b857008247d57e3ad890048b91a6f20125176ca49cabf213eaedddd7f69eb7915f85
6
+ metadata.gz: a02a998314d83f1e3c6c52323ac9bae4be8db96a16d0e736d7e9edc66194cd4dbe2da682b3c356329e5adc6172aecc79436d27dc1201ffa8aae3e112fd1970b1
7
+ data.tar.gz: 3f51ea1dfa2d700e93d21128fbfc0bdb236cb59e8d69095890c8835efe90c979e0a35dd6e6344c4f928c6ca60d22b8254affe0a333e4b2635c1db49d7f629664
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "slickgrid"
3
- gem.version = "2.4.5"
3
+ gem.version = "2.4.14"
4
4
  gem.authors = ["Erlingur Þorsteinsson"]
5
5
  gem.email = ["erlingur@rsf.is"]
6
6
  gem.description = %q{SlickGrid (6pac fork) gem for Rails}
@@ -1,36 +1,36 @@
1
- /***
2
- * A control to add a Column Picker (right+click on any column header to reveal the column picker)
3
- *
4
- * USAGE:
5
- *
6
- * Add the slick.columnpicker.(js|css) files and register it with the grid.
7
- *
8
- * Available options, by defining a columnPicker object:
9
- *
10
- * var options = {
11
- * enableCellNavigation: true,
12
- * columnPicker: {
13
- * columnTitle: "Columns", // default to empty string
14
- *
15
- * // the last 2 checkboxes titles
16
- * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns" (default:false)
17
- * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize" (default:false)
18
- * forceFitTitle: "Force fit columns", // default to "Force fit columns"
19
- * headerColumnValueExtractor: "Extract the column label" // default to column.name
20
- * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
21
- * }
22
- * };
23
- *
24
- * @class Slick.Controls.ColumnPicker
25
- * @constructor
26
- */
27
-
28
- 'use strict';
1
+ /***
2
+ * A control to add a Column Picker (right+click on any column header to reveal the column picker)
3
+ *
4
+ * USAGE:
5
+ *
6
+ * Add the slick.columnpicker.(js|css) files and register it with the grid.
7
+ *
8
+ * Available options, by defining a columnPicker object:
9
+ *
10
+ * var options = {
11
+ * enableCellNavigation: true,
12
+ * columnPicker: {
13
+ * columnTitle: "Columns", // default to empty string
14
+ *
15
+ * // the last 2 checkboxes titles
16
+ * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns" (default:false)
17
+ * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize" (default:false)
18
+ * forceFitTitle: "Force fit columns", // default to "Force fit columns"
19
+ * headerColumnValueExtractor: "Extract the column label" // default to column.name
20
+ * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
21
+ * }
22
+ * };
23
+ *
24
+ * @class Slick.Controls.ColumnPicker
25
+ * @constructor
26
+ */
29
27
 
30
28
  (function ($) {
29
+ 'use strict';
31
30
  function SlickColumnPicker(columns, grid, options) {
32
31
  var _grid = grid;
33
32
  var _options = options;
33
+ var $columnTitleElm;
34
34
  var $list;
35
35
  var $menu;
36
36
  var columnCheckboxes;
@@ -56,13 +56,13 @@
56
56
  _options = $.extend({}, defaults, options);
57
57
 
58
58
  $menu = $("<div class='slick-columnpicker' style='display:none' />").appendTo(document.body);
59
- var $close = $("<button type='button' class='close' data-dismiss='slick-columnpicker' aria-label='Close'><span class='close' aria-hidden='true'>&times;</span></button>").appendTo($menu);
59
+ $("<button type='button' class='close' data-dismiss='slick-columnpicker' aria-label='Close'><span class='close' aria-hidden='true'>&times;</span></button>").appendTo($menu);
60
60
 
61
61
  // user could pass a title on top of the columns list
62
- if(_options.columnPickerTitle || (_options.columnPicker && _options.columnPicker.columnTitle)) {
62
+ if (_options.columnPickerTitle || (_options.columnPicker && _options.columnPicker.columnTitle)) {
63
63
  var columnTitle = _options.columnPickerTitle || _options.columnPicker.columnTitle;
64
- var $title = $("<div class='title'/>").append(columnTitle);
65
- $title.appendTo($menu);
64
+ $columnTitleElm = $("<div class='title'/>").append(columnTitle);
65
+ $columnTitleElm.appendTo($menu);
66
66
  }
67
67
 
68
68
  $menu.on("click", updateColumn);
@@ -96,9 +96,10 @@
96
96
  columnCheckboxes = [];
97
97
 
98
98
  var $li, $input;
99
- var columnLabel;
99
+ var columnLabel, excludeCssClass;
100
100
  for (var i = 0; i < columns.length; i++) {
101
- $li = $("<li />").appendTo($list);
101
+ excludeCssClass = columns[i].excludeFromColumnPicker ? "hidden" : "";
102
+ $li = $('<li class="' + excludeCssClass + '" />').appendTo($list);
102
103
  $input = $("<input type='checkbox' />").data("column-id", columns[i].id);
103
104
  columnCheckboxes.push($input);
104
105
 
@@ -111,7 +112,7 @@
111
112
  } else {
112
113
  columnLabel = defaults.headerColumnValueExtractor(columns[i]);
113
114
  }
114
-
115
+
115
116
  $("<label />")
116
117
  .html(columnLabel)
117
118
  .prepend($input)
@@ -127,9 +128,9 @@
127
128
  $li = $("<li />").appendTo($list);
128
129
  $input = $("<input type='checkbox' />").data("option", "autoresize");
129
130
  $("<label />")
130
- .text(forceFitTitle)
131
- .prepend($input)
132
- .appendTo($li);
131
+ .text(forceFitTitle)
132
+ .prepend($input)
133
+ .appendTo($li);
133
134
  if (_grid.getOptions().forceFitColumns) {
134
135
  $input.attr("checked", "checked");
135
136
  }
@@ -140,19 +141,19 @@
140
141
  $li = $("<li />").appendTo($list);
141
142
  $input = $("<input type='checkbox' />").data("option", "syncresize");
142
143
  $("<label />")
143
- .text(syncResizeTitle)
144
- .prepend($input)
145
- .appendTo($li);
144
+ .text(syncResizeTitle)
145
+ .prepend($input)
146
+ .appendTo($li);
146
147
  if (_grid.getOptions().syncColumnCellResize) {
147
148
  $input.attr("checked", "checked");
148
149
  }
149
150
  }
150
151
 
151
152
  $menu
152
- .css("top", e.pageY - 10)
153
- .css("left", e.pageX - 10)
154
- .css("max-height", $(window).height() - e.pageY -10)
155
- .fadeIn(_options.fadeSpeed);
153
+ .css("top", e.pageY - 10)
154
+ .css("left", e.pageX - 10)
155
+ .css("max-height", $(window).height() - e.pageY - 10)
156
+ .fadeIn(_options.fadeSpeed);
156
157
 
157
158
  $list.appendTo($menu);
158
159
  }
@@ -167,7 +168,7 @@
167
168
  var current = _grid.getColumns().slice(0);
168
169
  var ordered = new Array(columns.length);
169
170
  for (var i = 0; i < ordered.length; i++) {
170
- if ( _grid.getColumnIndex(columns[i].id) === undefined ) {
171
+ if (_grid.getColumnIndex(columns[i].id) === undefined) {
171
172
  // If the column doesn't return a value from getColumnIndex,
172
173
  // it is hidden. Leave it in this position.
173
174
  ordered[i] = columns[i];
@@ -179,22 +180,29 @@
179
180
  columns = ordered;
180
181
  }
181
182
 
183
+ /** Update the Titles of each sections (command, customTitle, ...) */
184
+ function updateAllTitles(gridMenuOptions) {
185
+ if ($columnTitleElm && $columnTitleElm.text) {
186
+ $columnTitleElm.text(gridMenuOptions.columnTitle);
187
+ }
188
+ }
189
+
182
190
  function updateColumn(e) {
183
191
  if ($(e.target).data("option") == "autoresize") {
184
192
  if (e.target.checked) {
185
- _grid.setOptions({forceFitColumns:true});
193
+ _grid.setOptions({ forceFitColumns: true });
186
194
  _grid.autosizeColumns();
187
195
  } else {
188
- _grid.setOptions({forceFitColumns:false});
196
+ _grid.setOptions({ forceFitColumns: false });
189
197
  }
190
198
  return;
191
199
  }
192
200
 
193
201
  if ($(e.target).data("option") == "syncresize") {
194
202
  if (e.target.checked) {
195
- _grid.setOptions({syncColumnCellResize:true});
203
+ _grid.setOptions({ syncColumnCellResize: true });
196
204
  } else {
197
- _grid.setOptions({syncColumnCellResize:false});
205
+ _grid.setOptions({ syncColumnCellResize: false });
198
206
  }
199
207
  return;
200
208
  }
@@ -213,7 +221,7 @@
213
221
  }
214
222
 
215
223
  _grid.setColumns(visibleColumns);
216
- onColumnsChanged.notify({columns: visibleColumns, grid: _grid});
224
+ onColumnsChanged.notify({ columns: visibleColumns, grid: _grid });
217
225
  }
218
226
  }
219
227
 
@@ -227,10 +235,11 @@
227
235
  "init": init,
228
236
  "getAllColumns": getAllColumns,
229
237
  "destroy": destroy,
238
+ "updateAllTitles": updateAllTitles,
230
239
  "onColumnsChanged": onColumnsChanged
231
240
  };
232
241
  }
233
242
 
234
243
  // Slick.Controls.ColumnPicker
235
- $.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}});
244
+ $.extend(true, window, { Slick: { Controls: { ColumnPicker: SlickColumnPicker } } });
236
245
  })(jQuery);
@@ -1,448 +1,462 @@
1
- /***
2
- * A control to add a Grid Menu (hambuger menu on top-right of the grid)
3
- *
4
- * USAGE:
5
- *
6
- * Add the slick.gridmenu.(js|css) files and register it with the grid.
7
- *
8
- * To specify a menu in a column header, extend the column definition like so:
9
- * var gridMenuControl = new Slick.Controls.GridMenu(columns, grid, options);
10
- *
11
- * Available grid options, by defining a gridMenu object:
12
- *
13
- * var options = {
14
- * enableCellNavigation: true,
15
- * gridMenu: {
16
- * customTitle: "Custom Menus", // default to empty string
17
- * columnTitle: "Columns", // default to empty string
18
- * iconImage: "../slickgrid/drag-handle.png", // this is the Grid Menu icon (hamburger icon)
19
- * iconCssClass: "fa fa-bars", // you can provide iconImage OR iconCssClass
20
- * leaveOpen: false, // do we want to leave the Grid Menu open after a command execution? (false by default)
21
- * menuWidth: 18, // width that will be use to resize the column header container (18 by default)
22
- * resizeOnShowHeaderRow: false, // false by default
23
- *
24
- * // the last 2 checkboxes titles
25
- * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns"
26
- * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize"
27
- * forceFitTitle: "Force fit columns", // default to "Force fit columns"
28
- * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
29
- *
30
- * customItems: [
31
- * {
32
- * // custom menu item options
33
- * },
34
- * {
35
- * // custom menu item options
36
- * }
37
- * ]
38
- * }
39
- * };
40
- *
41
- *
42
- * Available custom menu item options:
43
- * title: Menu item text.
44
- * divider: Whether the current item is a divider, not an actual command.
45
- * disabled: Whether the item is disabled.
46
- * tooltip: Item tooltip.
47
- * command: A command identifier to be passed to the onCommand event handlers.
48
- * iconCssClass: A CSS class to be added to the menu item icon.
49
- * iconImage: A url to the icon image.
50
- *
51
- *
52
- * The plugin exposes the following events:
53
- * onBeforeMenuShow: Fired before the menu is shown. You can customize the menu or dismiss it by returning false.
54
- * * ONLY works with a jQuery event (as per slick.core code), so we cannot notify when it's a button event (when grid menu is attached to an external button, not the hamburger menu)
55
- * Event args:
56
- * grid: Reference to the grid.
57
- * column: Column definition.
58
- * menu: Menu options. Note that you can change the menu items here.
59
- *
60
- * onMenuClose: Fired when the menu is closing.
61
- * Event args:
62
- * grid: Reference to the grid.
63
- * column: Column definition.
64
- * menu: Menu options. Note that you can change the menu items here.
65
- *
66
- * onCommand: Fired on menu item click for buttons with 'command' specified.
67
- * Event args:
68
- * grid: Reference to the grid.
69
- * column: Column definition.
70
- * command: Button command identified.
71
- * button: Button options. Note that you can change the button options in your
72
- * event handler, and the column header will be automatically updated to
73
- * reflect them. This is useful if you want to implement something like a
74
- * toggle button.
75
- *
76
- *
77
- * @param options {Object} Options:
78
- * buttonCssClass: an extra CSS class to add to the menu button
79
- * buttonImage: a url to the menu button image (default '../slickgrid/down.gif')
80
- * @class Slick.Controls.GridMenu
81
- * @constructor
82
- */
83
-
84
- 'use strict';
85
-
86
- (function ($) {
87
- // register namespace
88
- $.extend(true, window, {
89
- "Slick": {
90
- "Controls": {
91
- "GridMenu": SlickGridMenu
92
- }
1
+ /***
2
+ * A control to add a Grid Menu (hambuger menu on top-right of the grid)
3
+ *
4
+ * USAGE:
5
+ *
6
+ * Add the slick.gridmenu.(js|css) files and register it with the grid.
7
+ *
8
+ * To specify a menu in a column header, extend the column definition like so:
9
+ * var gridMenuControl = new Slick.Controls.GridMenu(columns, grid, options);
10
+ *
11
+ * Available grid options, by defining a gridMenu object:
12
+ *
13
+ * var options = {
14
+ * enableCellNavigation: true,
15
+ * gridMenu: {
16
+ * customTitle: "Custom Menus", // default to empty string
17
+ * columnTitle: "Columns", // default to empty string
18
+ * iconImage: "../slickgrid/drag-handle.png", // this is the Grid Menu icon (hamburger icon)
19
+ * iconCssClass: "fa fa-bars", // you can provide iconImage OR iconCssClass
20
+ * leaveOpen: false, // do we want to leave the Grid Menu open after a command execution? (false by default)
21
+ * menuWidth: 18, // width that will be use to resize the column header container (18 by default)
22
+ * resizeOnShowHeaderRow: false, // false by default
23
+ *
24
+ * // the last 2 checkboxes titles
25
+ * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns"
26
+ * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize"
27
+ * forceFitTitle: "Force fit columns", // default to "Force fit columns"
28
+ * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
29
+ *
30
+ * customItems: [
31
+ * {
32
+ * // custom menu item options
33
+ * },
34
+ * {
35
+ * // custom menu item options
36
+ * }
37
+ * ]
38
+ * }
39
+ * };
40
+ *
41
+ *
42
+ * Available custom menu item options:
43
+ * title: Menu item text.
44
+ * divider: Whether the current item is a divider, not an actual command.
45
+ * disabled: Whether the item is disabled.
46
+ * tooltip: Item tooltip.
47
+ * command: A command identifier to be passed to the onCommand event handlers.
48
+ * iconCssClass: A CSS class to be added to the menu item icon.
49
+ * iconImage: A url to the icon image.
50
+ *
51
+ *
52
+ * The plugin exposes the following events:
53
+ * onBeforeMenuShow: Fired before the menu is shown. You can customize the menu or dismiss it by returning false.
54
+ * * ONLY works with a jQuery event (as per slick.core code), so we cannot notify when it's a button event (when grid menu is attached to an external button, not the hamburger menu)
55
+ * Event args:
56
+ * grid: Reference to the grid.
57
+ * column: Column definition.
58
+ * menu: Menu options. Note that you can change the menu items here.
59
+ *
60
+ * onMenuClose: Fired when the menu is closing.
61
+ * Event args:
62
+ * grid: Reference to the grid.
63
+ * column: Column definition.
64
+ * menu: Menu options. Note that you can change the menu items here.
65
+ *
66
+ * onCommand: Fired on menu item click for buttons with 'command' specified.
67
+ * Event args:
68
+ * grid: Reference to the grid.
69
+ * column: Column definition.
70
+ * command: Button command identified.
71
+ * button: Button options. Note that you can change the button options in your
72
+ * event handler, and the column header will be automatically updated to
73
+ * reflect them. This is useful if you want to implement something like a
74
+ * toggle button.
75
+ *
76
+ *
77
+ * @param options {Object} Options:
78
+ * buttonCssClass: an extra CSS class to add to the menu button
79
+ * buttonImage: a url to the menu button image (default '../slickgrid/down.gif')
80
+ * @class Slick.Controls.GridMenu
81
+ * @constructor
82
+ */
83
+
84
+ 'use strict';
85
+
86
+ (function ($) {
87
+ // register namespace
88
+ $.extend(true, window, {
89
+ "Slick": {
90
+ "Controls": {
91
+ "GridMenu": SlickGridMenu
93
92
  }
94
- });
93
+ }
94
+ });
95
+
96
+ function SlickGridMenu(columns, grid, options) {
97
+ var _grid = grid;
98
+ var _gridOptions;
99
+ var _gridUid = (grid && grid.getUID) ? grid.getUID() : '';
100
+ var _isMenuOpen = false;
101
+ var _options = options;
102
+ var _self = this;
103
+ var $customTitleElm;
104
+ var $columnTitleElm;
105
+ var $list;
106
+ var $button;
107
+ var $menu;
108
+ var columnCheckboxes;
109
+ var _defaults = {
110
+ hideForceFitButton: false,
111
+ hideSyncResizeButton: false,
112
+ fadeSpeed: 250,
113
+ forceFitTitle: "Force fit columns",
114
+ menuWidth: 18,
115
+ resizeOnShowHeaderRow: false,
116
+ syncResizeTitle: "Synchronous resize"
117
+ };
118
+
119
+ function init(grid) {
120
+ _gridOptions = grid.getOptions();
121
+ var gridMenuWidth = (_options.gridMenu && _options.gridMenu.menuWidth) || _defaults.menuWidth;
122
+ var $header;
123
+ if (_gridOptions && _gridOptions.frozenColumn && _gridOptions.frozenColumn > 0) {
124
+ $header = $('.' + _gridUid + ' .slick-header-right');
125
+ } else {
126
+ $header = $('.' + _gridUid + ' .slick-header-left');
127
+ }
128
+ $header.attr('style', 'width: calc(100% - ' + gridMenuWidth + 'px)');
95
129
 
96
- function SlickGridMenu(columns, grid, options) {
97
- var _grid = grid;
98
- var _gridOptions;
99
- var _gridUid = (grid && grid.getUID) ? grid.getUID() : '';
100
- var _isMenuOpen = false;
101
- var _options = options;
102
- var _self = this;
103
- var $list;
104
- var $button;
105
- var $menu;
106
- var columnCheckboxes;
107
- var _defaults = {
108
- hideForceFitButton: false,
109
- hideSyncResizeButton: false,
110
- fadeSpeed: 250,
111
- forceFitTitle: "Force fit columns",
112
- menuWidth: 18,
113
- resizeOnShowHeaderRow: false,
114
- syncResizeTitle: "Synchronous resize"
115
- };
116
-
117
- function init(grid) {
118
- _gridOptions = grid.getOptions();
119
- var gridMenuWidth = (_options.gridMenu && _options.gridMenu.menuWidth) || _defaults.menuWidth;
120
- var $header;
121
- if (_gridOptions && _gridOptions.frozenColumn && _gridOptions.frozenColumn > 0 ) {
122
- $header = $('.' + _gridUid + ' .slick-header-right');
123
- } else {
124
- $header = $('.' + _gridUid + ' .slick-header-left');
125
- }
126
- $header.attr('style', 'width: calc(100% - ' + gridMenuWidth +'px)');
130
+ // subscribe to the grid, when it's destroyed, we should also destroy the Grid Menu
131
+ grid.onBeforeDestroy.subscribe(destroy);
127
132
 
128
- // subscribe to the grid, when it's destroyed, we should also destroy the Grid Menu
129
- grid.onBeforeDestroy.subscribe(destroy);
133
+ // if header row is enabled, we need to resize it's width also
134
+ var enableResizeHeaderRow = (_options.gridMenu && _options.gridMenu.resizeOnShowHeaderRow != undefined) ? _options.gridMenu.resizeOnShowHeaderRow : _defaults.resizeOnShowHeaderRow;
135
+ if (enableResizeHeaderRow && _options.showHeaderRow) {
136
+ var $headerrow = $('.' + _gridUid + '.slick-headerrow');
137
+ $headerrow.attr('style', 'width: calc(100% - ' + gridMenuWidth + 'px)');
138
+ }
130
139
 
131
- // if header row is enabled, we need to resize it's width also
132
- var enableResizeHeaderRow = (_options.gridMenu && _options.gridMenu.resizeOnShowHeaderRow != undefined) ? _options.gridMenu.resizeOnShowHeaderRow : _defaults.resizeOnShowHeaderRow;
133
- if(enableResizeHeaderRow && _options.showHeaderRow) {
134
- var $headerrow = $('.' + _gridUid + '.slick-headerrow');
135
- $headerrow.attr('style', 'width: calc(100% - ' + gridMenuWidth +'px)');
136
- }
140
+ $button = $('<button class="slick-gridmenu-button"/>');
141
+ if (_options.gridMenu && _options.gridMenu.iconCssClass) {
142
+ $button.addClass(_options.gridMenu.iconCssClass);
143
+ } else {
144
+ var iconImage = (_options.gridMenu && _options.gridMenu.iconImage) ? _options.gridMenu.iconImage : "../slickgrid/drag-handle.png";
145
+ var $btnImage = $('<img src="' + iconImage + '"/>');
146
+ $btnImage.appendTo($button);
147
+ }
148
+ $button.insertBefore($header);
137
149
 
138
- $button = $('<button class="slick-gridmenu-button"/>');
139
- if (_options.gridMenu && _options.gridMenu.iconCssClass) {
140
- $button.addClass(_options.gridMenu.iconCssClass);
141
- } else {
142
- var iconImage = (_options.gridMenu && _options.gridMenu.iconImage) ? _options.gridMenu.iconImage :"../slickgrid/drag-handle.png";
143
- var $btnImage = $('<img src="' + iconImage + '"/>');
144
- $btnImage.appendTo($button);
145
- }
146
- $button.insertBefore($header);
150
+ $menu = $('<div class="slick-gridmenu ' + _gridUid + '" style="display: none" />').appendTo(document.body);
151
+ $('<button type="button" class="close" data-dismiss="slick-gridmenu" aria-label="Close"><span class="close" aria-hidden="true">&times;</span></button>').appendTo($menu);
147
152
 
148
- $menu = $('<div class="slick-gridmenu ' + _gridUid + '" style="display: none" />').appendTo(document.body);
149
- var $close = $('<button type="button" class="close" data-dismiss="slick-gridmenu" aria-label="Close"><span class="close" aria-hidden="true">&times;</span></button>').appendTo($menu);
153
+ var $customMenu = $('<div class="slick-gridmenu-custom" />');
154
+ $customMenu.appendTo($menu);
150
155
 
151
- var $customMenu = $('<div class="slick-gridmenu-custom" />');
152
- $customMenu.appendTo($menu);
156
+ // user could pass a title on top of the custom section
157
+ if (_options.gridMenu && _options.gridMenu.customTitle) {
158
+ $customTitleElm = $('<div class="title"/>').append(_options.gridMenu.customTitle);
159
+ $customTitleElm.appendTo($customMenu);
160
+ }
153
161
 
154
- // user could pass a title on top of the custom section
155
- if(_options.gridMenu && _options.gridMenu.customTitle) {
156
- var $title = $('<div class="title"/>').append(_options.gridMenu.customTitle);
157
- $title.appendTo($customMenu);
158
- }
162
+ populateCustomMenus(_options, $customMenu);
163
+ populateColumnPicker();
159
164
 
160
- populateCustomMenus(_options, $customMenu);
161
- populateColumnPicker();
165
+ // Hide the menu on outside click.
166
+ $(document.body).on("mousedown." + _gridUid, handleBodyMouseDown);
162
167
 
163
- // Hide the menu on outside click.
164
- $(document.body).on("mousedown." + _gridUid, handleBodyMouseDown);
168
+ // destroy the picker if user leaves the page
169
+ $(window).on("beforeunload", destroy);
165
170
 
166
- // destroy the picker if user leaves the page
167
- $(window).on("beforeunload", destroy);
171
+ // add on click handler for the Grid Menu itself
172
+ $button.on("click." + _gridUid, showGridMenu);
173
+ }
168
174
 
169
- // add on click handler for the Grid Menu itself
170
- $button.on("click." + _gridUid, showGridMenu);
171
- }
175
+ function destroy() {
176
+ _self.onBeforeMenuShow.unsubscribe();
177
+ _self.onMenuClose.unsubscribe();
178
+ _self.onCommand.unsubscribe();
179
+ _self.onColumnsChanged.unsubscribe();
180
+ _grid.onColumnsReordered.unsubscribe(updateColumnOrder);
181
+ _grid.onBeforeDestroy.unsubscribe();
182
+ $(document.body).off("mousedown." + _gridUid, handleBodyMouseDown);
183
+ $("div.slick-gridmenu." + _gridUid).hide(_options.fadeSpeed);
184
+ $menu.remove();
185
+ $button.remove();
186
+ }
172
187
 
173
- function destroy() {
174
- _self.onBeforeMenuShow.unsubscribe();
175
- _self.onMenuClose.unsubscribe();
176
- _self.onCommand.unsubscribe();
177
- _self.onColumnsChanged.unsubscribe();
178
- _grid.onColumnsReordered.unsubscribe(updateColumnOrder);
179
- _grid.onBeforeDestroy.unsubscribe();
180
- $(document.body).off("mousedown." + _gridUid, handleBodyMouseDown);
181
- $("div.slick-gridmenu." + _gridUid).hide(_options.fadeSpeed);
182
- $menu.remove();
183
- $button.remove();
188
+ function populateCustomMenus(options, $customMenu) {
189
+ // Construct the custom menu items.
190
+ if (!options.gridMenu || !options.gridMenu.customItems) {
191
+ return;
184
192
  }
193
+ for (var i = 0, ln = options.gridMenu.customItems.length; i < ln; i++) {
194
+ var item = options.gridMenu.customItems[i];
185
195
 
186
- function populateCustomMenus(options, $customMenu) {
187
- // Construct the custom menu items.
188
- if(!options.gridMenu || !options.gridMenu.customItems) {
189
- return;
196
+ var $li = $("<div class='slick-gridmenu-item'></div>")
197
+ .data("command", item.command || '')
198
+ .data("item", item)
199
+ .on("click", handleMenuItemClick)
200
+ .appendTo($customMenu);
201
+
202
+ if (item.disabled) {
203
+ $li.addClass("slick-gridmenu-item-disabled");
190
204
  }
191
- for (var i = 0, ln = options.gridMenu.customItems.length; i < ln; i++) {
192
- var item = options.gridMenu.customItems[i];
193
205
 
194
- var $li = $("<div class='slick-gridmenu-item'></div>")
195
- .data("command", item.command || '')
196
- .data("item", item)
197
- .on("click", handleMenuItemClick)
198
- .appendTo($customMenu);
206
+ if (item.divider) {
207
+ $li.addClass("slick-gridmenu-item-divider");
208
+ continue;
209
+ }
199
210
 
200
- if (item.disabled) {
201
- $li.addClass("slick-gridmenu-item-disabled");
202
- }
211
+ if (item.tooltip) {
212
+ $li.attr("title", item.tooltip);
213
+ }
203
214
 
204
- if (item.divider) {
205
- $li.addClass("slick-gridmenu-item-divider");
206
- continue;
207
- }
215
+ var $icon = $("<div class='slick-gridmenu-icon'></div>")
216
+ .appendTo($li);
208
217
 
209
- if (item.tooltip) {
210
- $li.attr("title", item.tooltip);
211
- }
218
+ if (item.iconCssClass) {
219
+ $icon.addClass(item.iconCssClass);
220
+ }
212
221
 
213
- var $icon = $("<div class='slick-gridmenu-icon'></div>")
214
- .appendTo($li);
222
+ if (item.iconImage) {
223
+ $icon.css("background-image", "url(" + item.iconImage + ")");
224
+ }
215
225
 
216
- if (item.iconCssClass) {
217
- $icon.addClass(item.iconCssClass);
218
- }
226
+ var $content = $("<span class='slick-gridmenu-content'></span>")
227
+ .text(item.title)
228
+ .appendTo($li);
229
+ }
230
+ }
219
231
 
220
- if (item.iconImage) {
221
- $icon.css("background-image", "url(" + item.iconImage + ")");
222
- }
232
+ /** Build the column picker, the code comes almost untouched from the file "slick.columnpicker.js" */
233
+ function populateColumnPicker() {
234
+ _grid.onColumnsReordered.subscribe(updateColumnOrder);
235
+ _options = $.extend({}, _defaults, _options);
223
236
 
224
- var $content = $("<span class='slick-gridmenu-content'></span>")
225
- .text(item.title)
226
- .appendTo($li);
227
- }
237
+ // user could pass a title on top of the columns list
238
+ if (_options.gridMenu && _options.gridMenu.columnTitle) {
239
+ $columnTitleElm = $('<div class="title"/>').append(_options.gridMenu.columnTitle);
240
+ $columnTitleElm.appendTo($menu);
228
241
  }
229
242
 
230
- /** Build the column picker, the code comes almost untouched from the file "slick.columnpicker.js" */
231
- function populateColumnPicker() {
232
- _grid.onColumnsReordered.subscribe(updateColumnOrder);
233
- _options = $.extend({}, _defaults, _options);
243
+ $menu.on("click", updateColumn);
244
+ $list = $('<span class="slick-gridmenu-list" />');
245
+ }
234
246
 
235
- // user could pass a title on top of the columns list
236
- if(_options.gridMenu && _options.gridMenu.columnTitle) {
237
- var $title = $('<div class="title"/>').append(_options.gridMenu.columnTitle);
238
- $title.appendTo($menu);
239
- }
247
+ function showGridMenu(e) {
248
+ e.preventDefault();
249
+ $list.empty();
240
250
 
241
- $menu.on("click", updateColumn);
242
- $list = $('<span class="slick-gridmenu-list" />');
243
- }
251
+ updateColumnOrder();
252
+ columnCheckboxes = [];
244
253
 
245
- function showGridMenu(e) {
246
- e.preventDefault();
247
- $list.empty();
248
-
249
- updateColumnOrder();
250
- columnCheckboxes = [];
251
-
252
- // notify of the onBeforeMenuShow only works when it's a jQuery event (as per slick.core code)
253
- // this mean that we cannot notify when the grid menu is attach to a button event
254
- if(typeof e.isPropagationStopped === "function") {
255
- if (_self.onBeforeMenuShow.notify({
256
- "grid": _grid,
257
- "menu": $menu
258
- }, e, _self) == false) {
259
- return;
260
- }
254
+ // notify of the onBeforeMenuShow only works when it's a jQuery event (as per slick.core code)
255
+ // this mean that we cannot notify when the grid menu is attach to a button event
256
+ if (typeof e.isPropagationStopped === "function") {
257
+ if (_self.onBeforeMenuShow.notify({
258
+ "grid": _grid,
259
+ "menu": $menu
260
+ }, e, _self) == false) {
261
+ return;
261
262
  }
263
+ }
262
264
 
263
- var $li, $input;
264
- for (var i = 0; i < columns.length; i++) {
265
- $li = $("<li />").appendTo($list);
266
- $input = $("<input type='checkbox' />").data("column-id", columns[i].id);
267
- columnCheckboxes.push($input);
265
+ var $li, $input, excludeCssClass;
266
+ for (var i = 0; i < columns.length; i++) {
267
+ excludeCssClass = columns[i].excludeFromGridMenu ? "hidden" : "";
268
+ $li = $('<li class="' + excludeCssClass + '" />').appendTo($list);
268
269
 
269
- if (_grid.getColumnIndex(columns[i].id) != null) {
270
- $input.attr("checked", "checked");
271
- }
270
+ $input = $("<input type='checkbox' />").data("column-id", columns[i].id);
271
+ columnCheckboxes.push($input);
272
272
 
273
- $("<label />")
274
- .html(columns[i].name)
275
- .prepend($input)
276
- .appendTo($li);
273
+ if (_grid.getColumnIndex(columns[i].id) != null) {
274
+ $input.attr("checked", "checked");
277
275
  }
278
276
 
279
- if (_options.gridMenu && (!_options.gridMenu.hideForceFitButton || !_options.gridMenu.hideSyncResizeButton)) {
280
- $("<hr/>").appendTo($list);
281
- }
277
+ $("<label />")
278
+ .html(columns[i].name)
279
+ .prepend($input)
280
+ .appendTo($li);
281
+ }
282
282
 
283
- if (!(_options.gridMenu && _options.gridMenu.hideForceFitButton)) {
284
- var forceFitTitle = (_options.gridMenu && _options.gridMenu.forceFitTitle) || _defaults.forceFitTitle;
285
- $li = $("<li />").appendTo($list);
286
- $input = $("<input type='checkbox' />").data("option", "autoresize");
287
- $("<label />")
288
- .text(forceFitTitle)
289
- .prepend($input)
290
- .appendTo($li);
291
- if (_grid.getOptions().forceFitColumns) {
292
- $input.attr("checked", "checked");
293
- }
283
+ if (_options.gridMenu && (!_options.gridMenu.hideForceFitButton || !_options.gridMenu.hideSyncResizeButton)) {
284
+ $("<hr/>").appendTo($list);
285
+ }
286
+
287
+ if (!(_options.gridMenu && _options.gridMenu.hideForceFitButton)) {
288
+ var forceFitTitle = (_options.gridMenu && _options.gridMenu.forceFitTitle) || _defaults.forceFitTitle;
289
+ $li = $("<li />").appendTo($list);
290
+ $input = $("<input type='checkbox' />").data("option", "autoresize");
291
+ $("<label />")
292
+ .text(forceFitTitle)
293
+ .prepend($input)
294
+ .appendTo($li);
295
+ if (_grid.getOptions().forceFitColumns) {
296
+ $input.attr("checked", "checked");
294
297
  }
298
+ }
295
299
 
296
- if (!(_options.gridMenu && _options.gridMenu.hideSyncResizeButton)) {
297
- var syncResizeTitle = (_options.gridMenu && _options.gridMenu.syncResizeTitle) || _defaults.syncResizeTitle;
298
- $li = $("<li />").appendTo($list);
299
- $input = $("<input type='checkbox' />").data("option", "syncresize");
300
- $("<label />")
301
- .text(syncResizeTitle)
302
- .prepend($input)
303
- .appendTo($li);
304
- if (_grid.getOptions().syncColumnCellResize) {
305
- $input.attr("checked", "checked");
306
- }
300
+ if (!(_options.gridMenu && _options.gridMenu.hideSyncResizeButton)) {
301
+ var syncResizeTitle = (_options.gridMenu && _options.gridMenu.syncResizeTitle) || _defaults.syncResizeTitle;
302
+ $li = $("<li />").appendTo($list);
303
+ $input = $("<input type='checkbox' />").data("option", "syncresize");
304
+ $("<label />")
305
+ .text(syncResizeTitle)
306
+ .prepend($input)
307
+ .appendTo($li);
308
+
309
+ if (_grid.getOptions().syncColumnCellResize) {
310
+ $input.attr("checked", "checked");
307
311
  }
312
+ }
308
313
 
309
- var gridMenuWidth = $menu.width();
314
+ $menu
315
+ .css("top", e.pageY + 10)
316
+ .css("left", e.pageX - $menu.width())
317
+ .css("max-height", $(window).height() - e.pageY - 10)
318
+ .fadeIn(_options.fadeSpeed);
310
319
 
311
- $menu
312
- .css("top", e.pageY + 10)
313
- .css("left", e.pageX - $menu.width())
314
- .css("max-height", $(window).height() - e.pageY -10)
315
- .fadeIn(_options.fadeSpeed);
320
+ $list.appendTo($menu);
321
+ _isMenuOpen = true;
322
+ }
316
323
 
317
- $list.appendTo($menu);
318
- _isMenuOpen = true;
324
+ function handleBodyMouseDown(e) {
325
+ if (($menu && $menu[0] != e.target && !$.contains($menu[0], e.target) && _isMenuOpen) || e.target.className == "close") {
326
+ hideMenu(e);
319
327
  }
328
+ }
320
329
 
321
- function handleBodyMouseDown(e) {
322
- if (($menu && $menu[0] != e.target && !$.contains($menu[0], e.target) && _isMenuOpen) || e.target.className == "close") {
323
- hideMenu(e);
324
- }
330
+ function handleMenuItemClick(e) {
331
+ var command = $(this).data("command");
332
+ var item = $(this).data("item");
333
+
334
+ if (item.disabled || item.divider) {
335
+ return;
336
+ }
337
+
338
+ // does the user want to leave open the Grid Menu after executing a command?
339
+ var leaveOpen = (_options.gridMenu && _options.gridMenu.leaveOpen) ? true : false;
340
+ if (!leaveOpen) {
341
+ hideMenu(e);
325
342
  }
326
343
 
327
- function handleMenuItemClick(e) {
328
- var command = $(this).data("command");
329
- var item = $(this).data("item");
344
+ if (command != null && command != '') {
345
+ _self.onCommand.notify({
346
+ "grid": _grid,
347
+ "command": command,
348
+ "item": item
349
+ }, e, _self);
350
+ }
330
351
 
331
- if (item.disabled || item.divider) {
332
- return;
333
- }
352
+ // Stop propagation so that it doesn't register as a header click event.
353
+ e.preventDefault();
354
+ e.stopPropagation();
355
+ }
334
356
 
335
- // does the user want to leave open the Grid Menu after executing a command?
336
- var leaveOpen = (_options.gridMenu && _options.gridMenu.leaveOpen) ? true : false;
337
- if(!leaveOpen) {
338
- hideMenu(e);
339
- }
357
+ function hideMenu(e) {
358
+ if ($menu) {
359
+ $menu.hide(_options.fadeSpeed);
360
+ _isMenuOpen = false;
340
361
 
341
- if (command != null && command != '') {
342
- _self.onCommand.notify({
343
- "grid": _grid,
344
- "command": command,
345
- "item": item
346
- }, e, _self);
362
+ if (_self.onMenuClose.notify({
363
+ "grid": _grid,
364
+ "menu": $menu
365
+ }, e, _self) == false) {
366
+ return;
347
367
  }
348
-
349
- // Stop propagation so that it doesn't register as a header click event.
350
- e.preventDefault();
351
- e.stopPropagation();
352
368
  }
369
+ }
353
370
 
354
- function hideMenu(e) {
355
- if ($menu) {
356
- $menu.hide(_options.fadeSpeed);
357
- _isMenuOpen = false;
371
+ /** Update the Titles of each sections (command, customTitle, ...) */
372
+ function updateAllTitles(gridMenuOptions) {
373
+ if ($customTitleElm && $customTitleElm.text) {
374
+ $customTitleElm.text(gridMenuOptions.customTitle);
375
+ }
376
+ if ($columnTitleElm && $columnTitleElm.text) {
377
+ $columnTitleElm.text(gridMenuOptions.columnTitle);
378
+ }
379
+ }
358
380
 
359
- if (_self.onMenuClose.notify({
360
- "grid": _grid,
361
- "menu": $menu
362
- }, e, _self) == false) {
363
- return;
364
- }
381
+ function updateColumnOrder() {
382
+ // Because columns can be reordered, we have to update the `columns`
383
+ // to reflect the new order, however we can't just take `grid.getColumns()`,
384
+ // as it does not include columns currently hidden by the picker.
385
+ // We create a new `columns` structure by leaving currently-hidden
386
+ // columns in their original ordinal position and interleaving the results
387
+ // of the current column sort.
388
+ var current = _grid.getColumns().slice(0);
389
+ var ordered = new Array(columns.length);
390
+ for (var i = 0; i < ordered.length; i++) {
391
+ if (_grid.getColumnIndex(columns[i].id) === undefined) {
392
+ // If the column doesn't return a value from getColumnIndex,
393
+ // it is hidden. Leave it in this position.
394
+ ordered[i] = columns[i];
395
+ } else {
396
+ // Otherwise, grab the next visible column.
397
+ ordered[i] = current.shift();
365
398
  }
366
399
  }
400
+ columns = ordered;
401
+ }
367
402
 
368
- function updateColumnOrder() {
369
- // Because columns can be reordered, we have to update the `columns`
370
- // to reflect the new order, however we can't just take `grid.getColumns()`,
371
- // as it does not include columns currently hidden by the picker.
372
- // We create a new `columns` structure by leaving currently-hidden
373
- // columns in their original ordinal position and interleaving the results
374
- // of the current column sort.
375
- var current = _grid.getColumns().slice(0);
376
- var ordered = new Array(columns.length);
377
- for (var i = 0; i < ordered.length; i++) {
378
- if ( _grid.getColumnIndex(columns[i].id) === undefined ) {
379
- // If the column doesn't return a value from getColumnIndex,
380
- // it is hidden. Leave it in this position.
381
- ordered[i] = columns[i];
382
- } else {
383
- // Otherwise, grab the next visible column.
384
- ordered[i] = current.shift();
385
- }
403
+ function updateColumn(e) {
404
+ if ($(e.target).data("option") == "autoresize") {
405
+ if (e.target.checked) {
406
+ _grid.setOptions({ forceFitColumns: true });
407
+ _grid.autosizeColumns();
408
+ } else {
409
+ _grid.setOptions({ forceFitColumns: false });
386
410
  }
387
- columns = ordered;
411
+ return;
388
412
  }
389
413
 
390
- function updateColumn(e) {
391
- if ($(e.target).data("option") == "autoresize") {
392
- if (e.target.checked) {
393
- _grid.setOptions({forceFitColumns:true});
394
- _grid.autosizeColumns();
395
- } else {
396
- _grid.setOptions({forceFitColumns:false});
397
- }
398
- return;
414
+ if ($(e.target).data("option") == "syncresize") {
415
+ if (e.target.checked) {
416
+ _grid.setOptions({ syncColumnCellResize: true });
417
+ } else {
418
+ _grid.setOptions({ syncColumnCellResize: false });
399
419
  }
420
+ return;
421
+ }
400
422
 
401
- if ($(e.target).data("option") == "syncresize") {
402
- if (e.target.checked) {
403
- _grid.setOptions({syncColumnCellResize:true});
404
- } else {
405
- _grid.setOptions({syncColumnCellResize:false});
423
+ if ($(e.target).is(":checkbox")) {
424
+ var visibleColumns = [];
425
+ $.each(columnCheckboxes, function (i, e) {
426
+ if ($(this).is(":checked")) {
427
+ visibleColumns.push(columns[i]);
406
428
  }
429
+ });
430
+
431
+ if (!visibleColumns.length) {
432
+ $(e.target).attr("checked", "checked");
407
433
  return;
408
434
  }
409
435
 
410
- if ($(e.target).is(":checkbox")) {
411
- var visibleColumns = [];
412
- $.each(columnCheckboxes, function (i, e) {
413
- if ($(this).is(":checked")) {
414
- visibleColumns.push(columns[i]);
415
- }
416
- });
417
-
418
- if (!visibleColumns.length) {
419
- $(e.target).attr("checked", "checked");
420
- return;
421
- }
422
-
423
- _grid.setColumns(visibleColumns);
424
- _self.onColumnsChanged.notify({
425
- "grid": _grid,
426
- "columns": visibleColumns
427
- }, e, _self);
428
- }
436
+ _grid.setColumns(visibleColumns);
437
+ _self.onColumnsChanged.notify({
438
+ "grid": _grid,
439
+ "columns": visibleColumns
440
+ }, e, _self);
429
441
  }
442
+ }
430
443
 
431
- init(_grid);
432
-
433
- function getAllColumns() {
434
- return columns;
435
- }
444
+ init(_grid);
436
445
 
437
- $.extend(this, {
438
- "init": init,
439
- "getAllColumns": getAllColumns,
440
- "destroy": destroy,
441
- "showGridMenu": showGridMenu,
442
- "onBeforeMenuShow": new Slick.Event(),
443
- "onMenuClose": new Slick.Event(),
444
- "onCommand": new Slick.Event(),
445
- "onColumnsChanged": new Slick.Event()
446
- });
446
+ function getAllColumns() {
447
+ return columns;
447
448
  }
448
- })(jQuery);
449
+
450
+ $.extend(this, {
451
+ "init": init,
452
+ "getAllColumns": getAllColumns,
453
+ "destroy": destroy,
454
+ "showGridMenu": showGridMenu,
455
+ "updateAllTitles": updateAllTitles,
456
+ "onBeforeMenuShow": new Slick.Event(),
457
+ "onMenuClose": new Slick.Event(),
458
+ "onCommand": new Slick.Event(),
459
+ "onColumnsChanged": new Slick.Event()
460
+ });
461
+ }
462
+ })(jQuery);