slickgrid 2.3.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +30 -0
- data/lib/slickgrid.rb +6 -0
- data/lib/slickgrid/version.rb +3 -0
- data/slickgrid.gemspec +20 -0
- data/vendor/assets/images/slickgrid/CheckboxN.png +0 -0
- data/vendor/assets/images/slickgrid/CheckboxY.png +0 -0
- data/vendor/assets/images/slickgrid/GrpCheckboxN.png +0 -0
- data/vendor/assets/images/slickgrid/GrpCheckboxY.png +0 -0
- data/vendor/assets/images/slickgrid/actions.gif +0 -0
- data/vendor/assets/images/slickgrid/ajax-loader-small.gif +0 -0
- data/vendor/assets/images/slickgrid/arrow-right.gif +0 -0
- data/vendor/assets/images/slickgrid/arrow_redo.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_right_peppermint.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_right_spearmint.png +0 -0
- data/vendor/assets/images/slickgrid/arrow_undo.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_blue.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_star.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_toggle_minus.png +0 -0
- data/vendor/assets/images/slickgrid/bullet_toggle_plus.png +0 -0
- data/vendor/assets/images/slickgrid/calendar.gif +0 -0
- data/vendor/assets/images/slickgrid/collapse.gif +0 -0
- data/vendor/assets/images/slickgrid/comment_yellow.gif +0 -0
- data/vendor/assets/images/slickgrid/delete.png +0 -0
- data/vendor/assets/images/slickgrid/down.gif +0 -0
- data/vendor/assets/images/slickgrid/drag-handle.png +0 -0
- data/vendor/assets/images/slickgrid/editor-helper-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/expand.gif +0 -0
- data/vendor/assets/images/slickgrid/header-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/header-columns-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/header-columns-over-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/help.png +0 -0
- data/vendor/assets/images/slickgrid/info.gif +0 -0
- data/vendor/assets/images/slickgrid/listview.gif +0 -0
- data/vendor/assets/images/slickgrid/pencil.gif +0 -0
- data/vendor/assets/images/slickgrid/row-over-bg.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-asc.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-asc.png +0 -0
- data/vendor/assets/images/slickgrid/sort-desc.gif +0 -0
- data/vendor/assets/images/slickgrid/sort-desc.png +0 -0
- data/vendor/assets/images/slickgrid/stripes.png +0 -0
- data/vendor/assets/images/slickgrid/tag_red.png +0 -0
- data/vendor/assets/images/slickgrid/tick.png +0 -0
- data/vendor/assets/images/slickgrid/user_identity.gif +0 -0
- data/vendor/assets/images/slickgrid/user_identity_plus.gif +0 -0
- data/vendor/assets/javascripts/slickgrid.js +5 -0
- data/vendor/assets/javascripts/slickgrid/controls/columnpicker.js +221 -0
- data/vendor/assets/javascripts/slickgrid/controls/gridmenu.js +429 -0
- data/vendor/assets/javascripts/slickgrid/controls/pager.js +154 -0
- data/vendor/assets/javascripts/slickgrid/core.js +493 -0
- data/vendor/assets/javascripts/slickgrid/dataview.js +1220 -0
- data/vendor/assets/javascripts/slickgrid/editors.js +640 -0
- data/vendor/assets/javascripts/slickgrid/formatters.js +65 -0
- data/vendor/assets/javascripts/slickgrid/grid.js +3990 -0
- data/vendor/assets/javascripts/slickgrid/groupitemmetadataprovider.js +172 -0
- data/vendor/assets/javascripts/slickgrid/plugins/autotooltips.js +83 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellcopymanager.js +88 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js +452 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellrangedecorator.js +72 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellrangeselector.js +123 -0
- data/vendor/assets/javascripts/slickgrid/plugins/cellselectionmodel.js +168 -0
- data/vendor/assets/javascripts/slickgrid/plugins/checkboxselectcolumn.js +202 -0
- data/vendor/assets/javascripts/slickgrid/plugins/draggablegrouping.js +207 -0
- data/vendor/assets/javascripts/slickgrid/plugins/headerbuttons.js +177 -0
- data/vendor/assets/javascripts/slickgrid/plugins/headermenu.js +296 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowdetailview.js +455 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowmovemanager.js +138 -0
- data/vendor/assets/javascripts/slickgrid/plugins/rowselectionmodel.js +191 -0
- data/vendor/assets/javascripts/slickgrid/remotemodel.js +169 -0
- data/vendor/assets/stylesheets/slickgrid.scss +1 -0
- data/vendor/assets/stylesheets/slickgrid/controls/columnpicker.css +46 -0
- data/vendor/assets/stylesheets/slickgrid/controls/gridmenu.css +113 -0
- data/vendor/assets/stylesheets/slickgrid/controls/pager.css +41 -0
- data/vendor/assets/stylesheets/slickgrid/default-theme.css +132 -0
- data/vendor/assets/stylesheets/slickgrid/grid.css +189 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/headerbuttons.css +39 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/headermenu.css +59 -0
- data/vendor/assets/stylesheets/slickgrid/plugins/rowdetailview.css +39 -0
- metadata +165 -0
@@ -0,0 +1,72 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellRangeDecorator": CellRangeDecorator
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
/***
|
10
|
+
* Displays an overlay on top of a given cell range.
|
11
|
+
*
|
12
|
+
* TODO:
|
13
|
+
* Currently, it blocks mouse events to DOM nodes behind it.
|
14
|
+
* Use FF and WebKit-specific "pointer-events" CSS style, or some kind of event forwarding.
|
15
|
+
* Could also construct the borders separately using 4 individual DIVs.
|
16
|
+
*
|
17
|
+
* @param {Grid} grid
|
18
|
+
* @param {Object} options
|
19
|
+
*/
|
20
|
+
function CellRangeDecorator(grid, options) {
|
21
|
+
var _elem;
|
22
|
+
var _defaults = {
|
23
|
+
selectionCssClass: 'slick-range-decorator',
|
24
|
+
selectionCss: {
|
25
|
+
"zIndex": "9999",
|
26
|
+
"border": "2px dashed red"
|
27
|
+
},
|
28
|
+
offset: {
|
29
|
+
top: -1,
|
30
|
+
left: -1,
|
31
|
+
height: -2,
|
32
|
+
width: -2
|
33
|
+
}
|
34
|
+
};
|
35
|
+
|
36
|
+
options = $.extend(true, {}, _defaults, options);
|
37
|
+
|
38
|
+
|
39
|
+
function show(range) {
|
40
|
+
if (!_elem) {
|
41
|
+
_elem = $("<div></div>", {css: options.selectionCss})
|
42
|
+
.addClass(options.selectionCssClass)
|
43
|
+
.css("position", "absolute")
|
44
|
+
.appendTo(grid.getCanvasNode());
|
45
|
+
}
|
46
|
+
|
47
|
+
var from = grid.getCellNodeBox(range.fromRow, range.fromCell);
|
48
|
+
var to = grid.getCellNodeBox(range.toRow, range.toCell);
|
49
|
+
|
50
|
+
_elem.css({
|
51
|
+
top: from.top + options.offset.top,
|
52
|
+
left: from.left + options.offset.left,
|
53
|
+
height: to.bottom - from.top + options.offset.height,
|
54
|
+
width: to.right - from.left + options.offset.width
|
55
|
+
});
|
56
|
+
|
57
|
+
return _elem;
|
58
|
+
}
|
59
|
+
|
60
|
+
function hide() {
|
61
|
+
if (_elem) {
|
62
|
+
_elem.remove();
|
63
|
+
_elem = null;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
$.extend(this, {
|
68
|
+
"show": show,
|
69
|
+
"hide": hide
|
70
|
+
});
|
71
|
+
}
|
72
|
+
})(jQuery);
|
@@ -0,0 +1,123 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellRangeSelector": CellRangeSelector
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function CellRangeSelector(options) {
|
10
|
+
var _grid;
|
11
|
+
var _currentlySelectedRange;
|
12
|
+
var _canvas;
|
13
|
+
var _dragging;
|
14
|
+
var _decorator;
|
15
|
+
var _self = this;
|
16
|
+
var _handler = new Slick.EventHandler();
|
17
|
+
var _defaults = {
|
18
|
+
selectionCss: {
|
19
|
+
"border": "2px dashed blue"
|
20
|
+
}
|
21
|
+
};
|
22
|
+
|
23
|
+
function init(grid) {
|
24
|
+
options = $.extend(true, {}, _defaults, options);
|
25
|
+
_decorator = options.cellDecorator || new Slick.CellRangeDecorator(grid, options);
|
26
|
+
_grid = grid;
|
27
|
+
_canvas = _grid.getCanvasNode();
|
28
|
+
_handler
|
29
|
+
.subscribe(_grid.onDragInit, handleDragInit)
|
30
|
+
.subscribe(_grid.onDragStart, handleDragStart)
|
31
|
+
.subscribe(_grid.onDrag, handleDrag)
|
32
|
+
.subscribe(_grid.onDragEnd, handleDragEnd);
|
33
|
+
}
|
34
|
+
|
35
|
+
function destroy() {
|
36
|
+
_handler.unsubscribeAll();
|
37
|
+
}
|
38
|
+
|
39
|
+
function getCellDecorator() {
|
40
|
+
return _decorator;
|
41
|
+
}
|
42
|
+
|
43
|
+
function handleDragInit(e, dd) {
|
44
|
+
// prevent the grid from cancelling drag'n'drop by default
|
45
|
+
e.stopImmediatePropagation();
|
46
|
+
}
|
47
|
+
|
48
|
+
function handleDragStart(e, dd) {
|
49
|
+
var cell = _grid.getCellFromEvent(e);
|
50
|
+
if (_self.onBeforeCellRangeSelected.notify(cell) !== false) {
|
51
|
+
if (_grid.canCellBeSelected(cell.row, cell.cell)) {
|
52
|
+
_dragging = true;
|
53
|
+
e.stopImmediatePropagation();
|
54
|
+
}
|
55
|
+
}
|
56
|
+
if (!_dragging) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
|
60
|
+
_grid.focus();
|
61
|
+
|
62
|
+
var start = _grid.getCellFromPoint(
|
63
|
+
dd.startX - $(_canvas).offset().left,
|
64
|
+
dd.startY - $(_canvas).offset().top);
|
65
|
+
|
66
|
+
dd.range = {start: start, end: {}};
|
67
|
+
_currentlySelectedRange = dd.range;
|
68
|
+
return _decorator.show(new Slick.Range(start.row, start.cell));
|
69
|
+
}
|
70
|
+
|
71
|
+
function handleDrag(e, dd) {
|
72
|
+
if (!_dragging) {
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
e.stopImmediatePropagation();
|
76
|
+
|
77
|
+
var end = _grid.getCellFromPoint(
|
78
|
+
e.pageX - $(_canvas).offset().left,
|
79
|
+
e.pageY - $(_canvas).offset().top);
|
80
|
+
|
81
|
+
if (!_grid.canCellBeSelected(end.row, end.cell)) {
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
|
85
|
+
dd.range.end = end;
|
86
|
+
_currentlySelectedRange = dd.range;
|
87
|
+
_decorator.show(new Slick.Range(dd.range.start.row, dd.range.start.cell, end.row, end.cell));
|
88
|
+
}
|
89
|
+
|
90
|
+
function handleDragEnd(e, dd) {
|
91
|
+
if (!_dragging) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
|
95
|
+
_dragging = false;
|
96
|
+
e.stopImmediatePropagation();
|
97
|
+
|
98
|
+
_decorator.hide();
|
99
|
+
_self.onCellRangeSelected.notify({
|
100
|
+
range: new Slick.Range(
|
101
|
+
dd.range.start.row,
|
102
|
+
dd.range.start.cell,
|
103
|
+
dd.range.end.row,
|
104
|
+
dd.range.end.cell
|
105
|
+
)
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
function getCurrentRange() {
|
110
|
+
return _currentlySelectedRange;
|
111
|
+
}
|
112
|
+
|
113
|
+
$.extend(this, {
|
114
|
+
"init": init,
|
115
|
+
"destroy": destroy,
|
116
|
+
"getCellDecorator": getCellDecorator,
|
117
|
+
"getCurrentRange": getCurrentRange,
|
118
|
+
|
119
|
+
"onBeforeCellRangeSelected": new Slick.Event(),
|
120
|
+
"onCellRangeSelected": new Slick.Event()
|
121
|
+
});
|
122
|
+
}
|
123
|
+
})(jQuery);
|
@@ -0,0 +1,168 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellSelectionModel": CellSelectionModel
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function CellSelectionModel(options) {
|
10
|
+
var _grid;
|
11
|
+
var _canvas;
|
12
|
+
var _ranges = [];
|
13
|
+
var _self = this;
|
14
|
+
var _selector;
|
15
|
+
|
16
|
+
if (typeof options === "undefined" || typeof options.cellRangeSelector === "undefined") {
|
17
|
+
_selector = new Slick.CellRangeSelector({
|
18
|
+
"selectionCss": {
|
19
|
+
"border": "2px solid black"
|
20
|
+
}
|
21
|
+
});
|
22
|
+
} else {
|
23
|
+
_selector = options.cellRangeSelector;
|
24
|
+
}
|
25
|
+
|
26
|
+
var _options;
|
27
|
+
var _defaults = {
|
28
|
+
selectActiveCell: true
|
29
|
+
};
|
30
|
+
|
31
|
+
function init(grid) {
|
32
|
+
_options = $.extend(true, {}, _defaults, options);
|
33
|
+
_grid = grid;
|
34
|
+
_canvas = _grid.getCanvasNode();
|
35
|
+
_grid.onActiveCellChanged.subscribe(handleActiveCellChange);
|
36
|
+
_grid.onKeyDown.subscribe(handleKeyDown);
|
37
|
+
grid.registerPlugin(_selector);
|
38
|
+
_selector.onCellRangeSelected.subscribe(handleCellRangeSelected);
|
39
|
+
_selector.onBeforeCellRangeSelected.subscribe(handleBeforeCellRangeSelected);
|
40
|
+
}
|
41
|
+
|
42
|
+
function destroy() {
|
43
|
+
_grid.onActiveCellChanged.unsubscribe(handleActiveCellChange);
|
44
|
+
_grid.onKeyDown.unsubscribe(handleKeyDown);
|
45
|
+
_selector.onCellRangeSelected.unsubscribe(handleCellRangeSelected);
|
46
|
+
_selector.onBeforeCellRangeSelected.unsubscribe(handleBeforeCellRangeSelected);
|
47
|
+
_grid.unregisterPlugin(_selector);
|
48
|
+
}
|
49
|
+
|
50
|
+
function removeInvalidRanges(ranges) {
|
51
|
+
var result = [];
|
52
|
+
|
53
|
+
for (var i = 0; i < ranges.length; i++) {
|
54
|
+
var r = ranges[i];
|
55
|
+
if (_grid.canCellBeSelected(r.fromRow, r.fromCell) && _grid.canCellBeSelected(r.toRow, r.toCell)) {
|
56
|
+
result.push(r);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return result;
|
61
|
+
}
|
62
|
+
|
63
|
+
function setSelectedRanges(ranges) {
|
64
|
+
// simple check for: empty selection didn't change, prevent firing onSelectedRangesChanged
|
65
|
+
if ((!_ranges || _ranges.length === 0) && (!ranges || ranges.length === 0)) { return; }
|
66
|
+
|
67
|
+
_ranges = removeInvalidRanges(ranges);
|
68
|
+
_self.onSelectedRangesChanged.notify(_ranges);
|
69
|
+
}
|
70
|
+
|
71
|
+
function getSelectedRanges() {
|
72
|
+
return _ranges;
|
73
|
+
}
|
74
|
+
|
75
|
+
function handleBeforeCellRangeSelected(e, args) {
|
76
|
+
if (_grid.getEditorLock().isActive()) {
|
77
|
+
e.stopPropagation();
|
78
|
+
return false;
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
function handleCellRangeSelected(e, args) {
|
83
|
+
_grid.setActiveCell(args.range.fromRow, args.range.fromCell, false, false, true);
|
84
|
+
setSelectedRanges([args.range]);
|
85
|
+
}
|
86
|
+
|
87
|
+
function handleActiveCellChange(e, args) {
|
88
|
+
if (_options.selectActiveCell && args.row != null && args.cell != null) {
|
89
|
+
setSelectedRanges([new Slick.Range(args.row, args.cell)]);
|
90
|
+
}
|
91
|
+
else if (!_options.selectActiveCell) {
|
92
|
+
// clear the previous selection once the cell changes
|
93
|
+
setSelectedRanges([]);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
function handleKeyDown(e) {
|
98
|
+
/***
|
99
|
+
* Кey codes
|
100
|
+
* 37 left
|
101
|
+
* 38 up
|
102
|
+
* 39 right
|
103
|
+
* 40 down
|
104
|
+
*/
|
105
|
+
var ranges, last;
|
106
|
+
var active = _grid.getActiveCell();
|
107
|
+
var metaKey = e.ctrlKey || e.metaKey;
|
108
|
+
|
109
|
+
if (active && e.shiftKey && !metaKey && !e.altKey &&
|
110
|
+
(e.which == 37 || e.which == 39 || e.which == 38 || e.which == 40)) {
|
111
|
+
|
112
|
+
ranges = getSelectedRanges();
|
113
|
+
if (!ranges.length)
|
114
|
+
ranges.push(new Slick.Range(active.row, active.cell));
|
115
|
+
|
116
|
+
// keyboard can work with last range only
|
117
|
+
last = ranges.pop();
|
118
|
+
|
119
|
+
// can't handle selection out of active cell
|
120
|
+
if (!last.contains(active.row, active.cell))
|
121
|
+
last = new Slick.Range(active.row, active.cell);
|
122
|
+
|
123
|
+
var dRow = last.toRow - last.fromRow,
|
124
|
+
dCell = last.toCell - last.fromCell,
|
125
|
+
// walking direction
|
126
|
+
dirRow = active.row == last.fromRow ? 1 : -1,
|
127
|
+
dirCell = active.cell == last.fromCell ? 1 : -1;
|
128
|
+
|
129
|
+
if (e.which == 37) {
|
130
|
+
dCell -= dirCell;
|
131
|
+
} else if (e.which == 39) {
|
132
|
+
dCell += dirCell;
|
133
|
+
} else if (e.which == 38) {
|
134
|
+
dRow -= dirRow;
|
135
|
+
} else if (e.which == 40) {
|
136
|
+
dRow += dirRow;
|
137
|
+
}
|
138
|
+
|
139
|
+
// define new selection range
|
140
|
+
var new_last = new Slick.Range(active.row, active.cell, active.row + dirRow * dRow, active.cell + dirCell * dCell);
|
141
|
+
if (removeInvalidRanges([new_last]).length) {
|
142
|
+
ranges.push(new_last);
|
143
|
+
var viewRow = dirRow > 0 ? new_last.toRow : new_last.fromRow;
|
144
|
+
var viewCell = dirCell > 0 ? new_last.toCell : new_last.fromCell;
|
145
|
+
_grid.scrollRowIntoView(viewRow);
|
146
|
+
_grid.scrollCellIntoView(viewRow, viewCell);
|
147
|
+
}
|
148
|
+
else
|
149
|
+
ranges.push(last);
|
150
|
+
|
151
|
+
setSelectedRanges(ranges);
|
152
|
+
|
153
|
+
e.preventDefault();
|
154
|
+
e.stopPropagation();
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
$.extend(this, {
|
159
|
+
"getSelectedRanges": getSelectedRanges,
|
160
|
+
"setSelectedRanges": setSelectedRanges,
|
161
|
+
|
162
|
+
"init": init,
|
163
|
+
"destroy": destroy,
|
164
|
+
|
165
|
+
"onSelectedRangesChanged": new Slick.Event()
|
166
|
+
});
|
167
|
+
}
|
168
|
+
})(jQuery);
|
@@ -0,0 +1,202 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CheckboxSelectColumn": CheckboxSelectColumn
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
|
10
|
+
function CheckboxSelectColumn(options) {
|
11
|
+
var _grid;
|
12
|
+
var _self = this;
|
13
|
+
var _handler = new Slick.EventHandler();
|
14
|
+
var _selectedRowsLookup = {};
|
15
|
+
var _defaults = {
|
16
|
+
columnId: "_checkbox_selector",
|
17
|
+
cssClass: null,
|
18
|
+
toolTip: "Select/Deselect All",
|
19
|
+
width: 30
|
20
|
+
};
|
21
|
+
|
22
|
+
var _options = $.extend(true, {}, _defaults, options);
|
23
|
+
|
24
|
+
function init(grid) {
|
25
|
+
_grid = grid;
|
26
|
+
_handler
|
27
|
+
.subscribe(_grid.onSelectedRowsChanged, handleSelectedRowsChanged)
|
28
|
+
.subscribe(_grid.onClick, handleClick)
|
29
|
+
.subscribe(_grid.onHeaderClick, handleHeaderClick)
|
30
|
+
.subscribe(_grid.onKeyDown, handleKeyDown);
|
31
|
+
}
|
32
|
+
|
33
|
+
function destroy() {
|
34
|
+
_handler.unsubscribeAll();
|
35
|
+
}
|
36
|
+
|
37
|
+
function handleSelectedRowsChanged(e, args) {
|
38
|
+
var UID = createUID();
|
39
|
+
var selectedRows = _grid.getSelectedRows();
|
40
|
+
var lookup = {}, row, i;
|
41
|
+
for (i = 0; i < selectedRows.length; i++) {
|
42
|
+
row = selectedRows[i];
|
43
|
+
lookup[row] = true;
|
44
|
+
if (lookup[row] !== _selectedRowsLookup[row]) {
|
45
|
+
_grid.invalidateRow(row);
|
46
|
+
delete _selectedRowsLookup[row];
|
47
|
+
}
|
48
|
+
}
|
49
|
+
for (i in _selectedRowsLookup) {
|
50
|
+
_grid.invalidateRow(i);
|
51
|
+
}
|
52
|
+
_selectedRowsLookup = lookup;
|
53
|
+
_grid.render();
|
54
|
+
|
55
|
+
if (selectedRows.length && selectedRows.length == _grid.getDataLength()) {
|
56
|
+
_grid.updateColumnHeader(_options.columnId, "<input id='header-selector" + UID + "' type='checkbox' checked='checked'><label for='header-selector" + UID + "'></label>", _options.toolTip);
|
57
|
+
} else {
|
58
|
+
_grid.updateColumnHeader(_options.columnId, "<input id='header-selector" + UID + "' type='checkbox'><label for='header-selector" + UID + "'></label>", _options.toolTip);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
function handleKeyDown(e, args) {
|
63
|
+
if (e.which == 32) {
|
64
|
+
if (_grid.getColumns()[args.cell].id === _options.columnId) {
|
65
|
+
// if editing, try to commit
|
66
|
+
if (!_grid.getEditorLock().isActive() || _grid.getEditorLock().commitCurrentEdit()) {
|
67
|
+
toggleRowSelection(args.row);
|
68
|
+
}
|
69
|
+
e.preventDefault();
|
70
|
+
e.stopImmediatePropagation();
|
71
|
+
}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
function handleClick(e, args) {
|
76
|
+
// clicking on a row select checkbox
|
77
|
+
if (_grid.getColumns()[args.cell].id === _options.columnId && $(e.target).is(":checkbox")) {
|
78
|
+
// if editing, try to commit
|
79
|
+
if (_grid.getEditorLock().isActive() && !_grid.getEditorLock().commitCurrentEdit()) {
|
80
|
+
e.preventDefault();
|
81
|
+
e.stopImmediatePropagation();
|
82
|
+
return;
|
83
|
+
}
|
84
|
+
|
85
|
+
toggleRowSelection(args.row);
|
86
|
+
e.stopPropagation();
|
87
|
+
e.stopImmediatePropagation();
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
function toggleRowSelection(row) {
|
92
|
+
if (_selectedRowsLookup[row]) {
|
93
|
+
_grid.setSelectedRows($.grep(_grid.getSelectedRows(), function (n) {
|
94
|
+
return n != row
|
95
|
+
}));
|
96
|
+
} else {
|
97
|
+
_grid.setSelectedRows(_grid.getSelectedRows().concat(row));
|
98
|
+
}
|
99
|
+
_grid.setActiveCell(row, getCheckboxColumnCellIndex());
|
100
|
+
_grid.focus();
|
101
|
+
}
|
102
|
+
|
103
|
+
function selectRows(rowArray) {
|
104
|
+
var i, l=rowArray.length, addRows = [];
|
105
|
+
for(i=0; i<l; i++) {
|
106
|
+
if (!_selectedRowsLookup[rowArray[i]]) {
|
107
|
+
addRows[addRows.length] = rowArray[i];
|
108
|
+
}
|
109
|
+
}
|
110
|
+
_grid.setSelectedRows(_grid.getSelectedRows().concat(addRows));
|
111
|
+
}
|
112
|
+
|
113
|
+
function deSelectRows(rowArray) {
|
114
|
+
var i, l=rowArray.length, removeRows = [];
|
115
|
+
for(i=0; i<l; i++) {
|
116
|
+
if (_selectedRowsLookup[rowArray[i]]) {
|
117
|
+
removeRows[removeRows.length] = rowArray[i];
|
118
|
+
}
|
119
|
+
}
|
120
|
+
_grid.setSelectedRows($.grep(_grid.getSelectedRows(), function (n) {
|
121
|
+
return removeRows.indexOf(n)<0
|
122
|
+
}));
|
123
|
+
}
|
124
|
+
|
125
|
+
function handleHeaderClick(e, args) {
|
126
|
+
if (args.column.id == _options.columnId && $(e.target).is(":checkbox")) {
|
127
|
+
// if editing, try to commit
|
128
|
+
if (_grid.getEditorLock().isActive() && !_grid.getEditorLock().commitCurrentEdit()) {
|
129
|
+
e.preventDefault();
|
130
|
+
e.stopImmediatePropagation();
|
131
|
+
return;
|
132
|
+
}
|
133
|
+
|
134
|
+
if ($(e.target).is(":checked")) {
|
135
|
+
var rows = [];
|
136
|
+
for (var i = 0; i < _grid.getDataLength(); i++) {
|
137
|
+
rows.push(i);
|
138
|
+
}
|
139
|
+
_grid.setSelectedRows(rows);
|
140
|
+
} else {
|
141
|
+
_grid.setSelectedRows([]);
|
142
|
+
}
|
143
|
+
e.stopPropagation();
|
144
|
+
e.stopImmediatePropagation();
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
var _checkboxColumnCellIndex = null;
|
149
|
+
|
150
|
+
function getCheckboxColumnCellIndex() {
|
151
|
+
if (_checkboxColumnCellIndex === null) {
|
152
|
+
_checkboxColumnCellIndex = 0;
|
153
|
+
var colArr = _grid.getColumns();
|
154
|
+
for (var i=0; i < colArr.length; i++) {
|
155
|
+
if (colArr[i].id == _options.columnId) {
|
156
|
+
_checkboxColumnCellIndex = i;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
return _checkboxColumnCellIndex;
|
161
|
+
}
|
162
|
+
|
163
|
+
function getColumnDefinition() {
|
164
|
+
var UID = createUID();
|
165
|
+
|
166
|
+
return {
|
167
|
+
id: _options.columnId,
|
168
|
+
name: "<input id='header-selector" + UID + "' type='checkbox'><label for='header-selector" + UID + "'></label>",
|
169
|
+
toolTip: _options.toolTip,
|
170
|
+
field: "sel",
|
171
|
+
width: _options.width,
|
172
|
+
resizable: false,
|
173
|
+
sortable: false,
|
174
|
+
cssClass: _options.cssClass,
|
175
|
+
formatter: checkboxSelectionFormatter
|
176
|
+
};
|
177
|
+
}
|
178
|
+
|
179
|
+
function createUID() {
|
180
|
+
return Math.round(10000000 * Math.random());
|
181
|
+
}
|
182
|
+
|
183
|
+
function checkboxSelectionFormatter(row, cell, value, columnDef, dataContext) {
|
184
|
+
var UID = createUID() + row;
|
185
|
+
|
186
|
+
if (dataContext) {
|
187
|
+
return _selectedRowsLookup[row]
|
188
|
+
? "<input id='selector" + UID + "' type='checkbox' checked='checked'><label for='selector" + UID + "'></label>"
|
189
|
+
: "<input id='selector" + UID + "' type='checkbox'><label for='selector" + UID + "'></label>";
|
190
|
+
}
|
191
|
+
return null;
|
192
|
+
}
|
193
|
+
|
194
|
+
$.extend(this, {
|
195
|
+
"init": init,
|
196
|
+
"destroy": destroy,
|
197
|
+
"deSelectRows": deSelectRows,
|
198
|
+
"selectRows": selectRows,
|
199
|
+
"getColumnDefinition": getColumnDefinition
|
200
|
+
});
|
201
|
+
}
|
202
|
+
})(jQuery);
|