slickgrid 2.4.5 → 2.4.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/slickgrid.gemspec +1 -1
- data/vendor/assets/javascripts/slickgrid/controls/columnpicker.js +61 -52
- data/vendor/assets/javascripts/slickgrid/controls/gridmenu.js +393 -379
- data/vendor/assets/javascripts/slickgrid/controls/pager.js +8 -8
- data/vendor/assets/javascripts/slickgrid/core.js +43 -7
- data/vendor/assets/javascripts/slickgrid/dataview.js +71 -23
- data/vendor/assets/javascripts/slickgrid/editors.js +11 -11
- data/vendor/assets/javascripts/slickgrid/grid.js +617 -98
- data/vendor/assets/javascripts/slickgrid/groupitemmetadataprovider.js +8 -4
- data/vendor/assets/javascripts/slickgrid/plugins/cellcopymanager.js +1 -1
- data/vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js +6 -6
- data/vendor/assets/javascripts/slickgrid/plugins/checkboxselectcolumn.js +10 -5
- data/vendor/assets/javascripts/slickgrid/plugins/draggablegrouping.js +11 -11
- data/vendor/assets/javascripts/slickgrid/plugins/headermenu.js +1 -1
- data/vendor/assets/javascripts/slickgrid/plugins/rowdetailview.js +28 -12
- data/vendor/assets/javascripts/slickgrid/plugins/rowmovemanager.js +1 -1
- data/vendor/assets/javascripts/slickgrid/plugins/rowselectionmodel.js +1 -1
- data/vendor/assets/javascripts/slickgrid/plugins/state.js +153 -0
- data/vendor/assets/javascripts/slickgrid/remotemodel.js +1 -1
- data/vendor/assets/stylesheets/slickgrid/controls/columnpicker.css +5 -0
- data/vendor/assets/stylesheets/slickgrid/controls/gridmenu.css +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c41868db700a74173821c903442e06312d69d5c7
|
4
|
+
data.tar.gz: 6e457a267a195e537b30ada036b56897319b38e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a02a998314d83f1e3c6c52323ac9bae4be8db96a16d0e736d7e9edc66194cd4dbe2da682b3c356329e5adc6172aecc79436d27dc1201ffa8aae3e112fd1970b1
|
7
|
+
data.tar.gz: 3f51ea1dfa2d700e93d21128fbfc0bdb236cb59e8d69095890c8835efe90c979e0a35dd6e6344c4f928c6ca60d22b8254affe0a333e4b2635c1db49d7f629664
|
data/slickgrid.gemspec
CHANGED
@@ -1,36 +1,36 @@
|
|
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
|
-
'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
|
-
|
59
|
+
$("<button type='button' class='close' data-dismiss='slick-columnpicker' aria-label='Close'><span class='close' aria-hidden='true'>×</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
|
-
|
65
|
-
$
|
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
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
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
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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 (
|
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
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
-
|
97
|
-
|
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
|
-
|
129
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
139
|
-
|
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">×</span></button>').appendTo($menu);
|
147
152
|
|
148
|
-
|
149
|
-
|
153
|
+
var $customMenu = $('<div class="slick-gridmenu-custom" />');
|
154
|
+
$customMenu.appendTo($menu);
|
150
155
|
|
151
|
-
|
152
|
-
|
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
|
-
|
155
|
-
|
156
|
-
var $title = $('<div class="title"/>').append(_options.gridMenu.customTitle);
|
157
|
-
$title.appendTo($customMenu);
|
158
|
-
}
|
162
|
+
populateCustomMenus(_options, $customMenu);
|
163
|
+
populateColumnPicker();
|
159
164
|
|
160
|
-
|
161
|
-
|
165
|
+
// Hide the menu on outside click.
|
166
|
+
$(document.body).on("mousedown." + _gridUid, handleBodyMouseDown);
|
162
167
|
|
163
|
-
|
164
|
-
|
168
|
+
// destroy the picker if user leaves the page
|
169
|
+
$(window).on("beforeunload", destroy);
|
165
170
|
|
166
|
-
|
167
|
-
|
171
|
+
// add on click handler for the Grid Menu itself
|
172
|
+
$button.on("click." + _gridUid, showGridMenu);
|
173
|
+
}
|
168
174
|
|
169
|
-
|
170
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
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
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
.appendTo($customMenu);
|
206
|
+
if (item.divider) {
|
207
|
+
$li.addClass("slick-gridmenu-item-divider");
|
208
|
+
continue;
|
209
|
+
}
|
199
210
|
|
200
|
-
|
201
|
-
|
202
|
-
|
211
|
+
if (item.tooltip) {
|
212
|
+
$li.attr("title", item.tooltip);
|
213
|
+
}
|
203
214
|
|
204
|
-
|
205
|
-
|
206
|
-
continue;
|
207
|
-
}
|
215
|
+
var $icon = $("<div class='slick-gridmenu-icon'></div>")
|
216
|
+
.appendTo($li);
|
208
217
|
|
209
|
-
|
210
|
-
|
211
|
-
|
218
|
+
if (item.iconCssClass) {
|
219
|
+
$icon.addClass(item.iconCssClass);
|
220
|
+
}
|
212
221
|
|
213
|
-
|
214
|
-
|
222
|
+
if (item.iconImage) {
|
223
|
+
$icon.css("background-image", "url(" + item.iconImage + ")");
|
224
|
+
}
|
215
225
|
|
216
|
-
|
217
|
-
|
218
|
-
|
226
|
+
var $content = $("<span class='slick-gridmenu-content'></span>")
|
227
|
+
.text(item.title)
|
228
|
+
.appendTo($li);
|
229
|
+
}
|
230
|
+
}
|
219
231
|
|
220
|
-
|
221
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
231
|
-
|
232
|
-
|
233
|
-
_options = $.extend({}, _defaults, _options);
|
243
|
+
$menu.on("click", updateColumn);
|
244
|
+
$list = $('<span class="slick-gridmenu-list" />');
|
245
|
+
}
|
234
246
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
$title.appendTo($menu);
|
239
|
-
}
|
247
|
+
function showGridMenu(e) {
|
248
|
+
e.preventDefault();
|
249
|
+
$list.empty();
|
240
250
|
|
241
|
-
|
242
|
-
|
243
|
-
}
|
251
|
+
updateColumnOrder();
|
252
|
+
columnCheckboxes = [];
|
244
253
|
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
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
|
-
|
270
|
-
|
271
|
-
}
|
270
|
+
$input = $("<input type='checkbox' />").data("column-id", columns[i].id);
|
271
|
+
columnCheckboxes.push($input);
|
272
272
|
|
273
|
-
|
274
|
-
|
275
|
-
.prepend($input)
|
276
|
-
.appendTo($li);
|
273
|
+
if (_grid.getColumnIndex(columns[i].id) != null) {
|
274
|
+
$input.attr("checked", "checked");
|
277
275
|
}
|
278
276
|
|
279
|
-
|
280
|
-
|
281
|
-
|
277
|
+
$("<label />")
|
278
|
+
.html(columns[i].name)
|
279
|
+
.prepend($input)
|
280
|
+
.appendTo($li);
|
281
|
+
}
|
282
282
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
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
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
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
|
-
|
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
|
-
|
312
|
-
|
313
|
-
|
314
|
-
.css("max-height", $(window).height() - e.pageY -10)
|
315
|
-
.fadeIn(_options.fadeSpeed);
|
320
|
+
$list.appendTo($menu);
|
321
|
+
_isMenuOpen = true;
|
322
|
+
}
|
316
323
|
|
317
|
-
|
318
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
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
|
-
|
328
|
-
|
329
|
-
|
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
|
-
|
332
|
-
|
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
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
}
|
357
|
+
function hideMenu(e) {
|
358
|
+
if ($menu) {
|
359
|
+
$menu.hide(_options.fadeSpeed);
|
360
|
+
_isMenuOpen = false;
|
340
361
|
|
341
|
-
if (
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
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
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
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
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
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
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
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
|
-
|
411
|
+
return;
|
388
412
|
}
|
389
413
|
|
390
|
-
|
391
|
-
if (
|
392
|
-
|
393
|
-
|
394
|
-
|
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
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
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
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
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
|
-
|
432
|
-
|
433
|
-
function getAllColumns() {
|
434
|
-
return columns;
|
435
|
-
}
|
444
|
+
init(_grid);
|
436
445
|
|
437
|
-
|
438
|
-
|
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
|
-
|
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);
|