slickgrid-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +75 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/fetch.sh +8 -0
- data/lib/slickgrid-rails.rb +1 -0
- data/lib/slickgrid/rails.rb +5 -0
- data/lib/slickgrid/rails/engine.rb +7 -0
- data/lib/slickgrid/rails/version.rb +6 -0
- data/lib/slickgrid/table.rb +72 -0
- data/slickgrid-rails.gemspec +22 -0
- data/vendor/assets/images/slick/actions.gif +0 -0
- data/vendor/assets/images/slick/ajax-loader-small.gif +0 -0
- data/vendor/assets/images/slick/arrow_redo.png +0 -0
- data/vendor/assets/images/slick/arrow_right_peppermint.png +0 -0
- data/vendor/assets/images/slick/arrow_right_spearmint.png +0 -0
- data/vendor/assets/images/slick/arrow_undo.png +0 -0
- data/vendor/assets/images/slick/bullet_blue.png +0 -0
- data/vendor/assets/images/slick/bullet_star.png +0 -0
- data/vendor/assets/images/slick/bullet_toggle_minus.png +0 -0
- data/vendor/assets/images/slick/bullet_toggle_plus.png +0 -0
- data/vendor/assets/images/slick/calendar.gif +0 -0
- data/vendor/assets/images/slick/collapse.gif +0 -0
- data/vendor/assets/images/slick/comment_yellow.gif +0 -0
- data/vendor/assets/images/slick/down.gif +0 -0
- data/vendor/assets/images/slick/drag-handle.png +0 -0
- data/vendor/assets/images/slick/editor-helper-bg.gif +0 -0
- data/vendor/assets/images/slick/expand.gif +0 -0
- data/vendor/assets/images/slick/header-bg.gif +0 -0
- data/vendor/assets/images/slick/header-columns-bg.gif +0 -0
- data/vendor/assets/images/slick/header-columns-over-bg.gif +0 -0
- data/vendor/assets/images/slick/help.png +0 -0
- data/vendor/assets/images/slick/info.gif +0 -0
- data/vendor/assets/images/slick/listview.gif +0 -0
- data/vendor/assets/images/slick/pencil.gif +0 -0
- data/vendor/assets/images/slick/row-over-bg.gif +0 -0
- data/vendor/assets/images/slick/sort-asc.gif +0 -0
- data/vendor/assets/images/slick/sort-asc.png +0 -0
- data/vendor/assets/images/slick/sort-desc.gif +0 -0
- data/vendor/assets/images/slick/sort-desc.png +0 -0
- data/vendor/assets/images/slick/stripes.png +0 -0
- data/vendor/assets/images/slick/tag_red.png +0 -0
- data/vendor/assets/images/slick/tick.png +0 -0
- data/vendor/assets/images/slick/user_identity.gif +0 -0
- data/vendor/assets/images/slick/user_identity_plus.gif +0 -0
- data/vendor/assets/javascripts/slick.js +4 -0
- data/vendor/assets/javascripts/slick/controls/columnpicker.js +106 -0
- data/vendor/assets/javascripts/slick/controls/pager.js +151 -0
- data/vendor/assets/javascripts/slick/core.js +424 -0
- data/vendor/assets/javascripts/slick/dataview.js +908 -0
- data/vendor/assets/javascripts/slick/editors.js +512 -0
- data/vendor/assets/javascripts/slick/formatters.js +55 -0
- data/vendor/assets/javascripts/slick/grid.js +2783 -0
- data/vendor/assets/javascripts/slick/groupitemmetadataprovider.js +139 -0
- data/vendor/assets/javascripts/slick/plugins/autotooltips.js +48 -0
- data/vendor/assets/javascripts/slick/plugins/cellcopymanager.js +86 -0
- data/vendor/assets/javascripts/slick/plugins/cellrangedecorator.js +64 -0
- data/vendor/assets/javascripts/slick/plugins/cellrangeselector.js +112 -0
- data/vendor/assets/javascripts/slick/plugins/cellselectionmodel.js +92 -0
- data/vendor/assets/javascripts/slick/plugins/checkboxselectcolumn.js +154 -0
- data/vendor/assets/javascripts/slick/plugins/rowmovemanager.js +132 -0
- data/vendor/assets/javascripts/slick/plugins/rowselectionmodel.js +187 -0
- data/vendor/assets/javascripts/slick/remotemodel.js +164 -0
- data/vendor/assets/stylesheets/slick/controls/columnpicker.css +30 -0
- data/vendor/assets/stylesheets/slick/controls/pager.css.scss +41 -0
- data/vendor/assets/stylesheets/slick/default-theme.css.scss +104 -0
- data/vendor/assets/stylesheets/slick/grid.css.scss +158 -0
- metadata +158 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"CellSelectionModel": CellSelectionModel
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
|
10
|
+
function CellSelectionModel(options) {
|
11
|
+
var _grid;
|
12
|
+
var _canvas;
|
13
|
+
var _ranges = [];
|
14
|
+
var _self = this;
|
15
|
+
var _selector = new Slick.CellRangeSelector({
|
16
|
+
"selectionCss": {
|
17
|
+
"border": "2px solid black"
|
18
|
+
}
|
19
|
+
});
|
20
|
+
var _options;
|
21
|
+
var _defaults = {
|
22
|
+
selectActiveCell: true
|
23
|
+
};
|
24
|
+
|
25
|
+
|
26
|
+
function init(grid) {
|
27
|
+
_options = $.extend(true, {}, _defaults, options);
|
28
|
+
_grid = grid;
|
29
|
+
_canvas = _grid.getCanvasNode();
|
30
|
+
_grid.onActiveCellChanged.subscribe(handleActiveCellChange);
|
31
|
+
grid.registerPlugin(_selector);
|
32
|
+
_selector.onCellRangeSelected.subscribe(handleCellRangeSelected);
|
33
|
+
_selector.onBeforeCellRangeSelected.subscribe(handleBeforeCellRangeSelected);
|
34
|
+
}
|
35
|
+
|
36
|
+
function destroy() {
|
37
|
+
_grid.onActiveCellChanged.unsubscribe(handleActiveCellChange);
|
38
|
+
_selector.onCellRangeSelected.unsubscribe(handleCellRangeSelected);
|
39
|
+
_selector.onBeforeCellRangeSelected.unsubscribe(handleBeforeCellRangeSelected);
|
40
|
+
_grid.unregisterPlugin(_selector);
|
41
|
+
}
|
42
|
+
|
43
|
+
function removeInvalidRanges(ranges) {
|
44
|
+
var result = [];
|
45
|
+
|
46
|
+
for (var i = 0; i < ranges.length; i++) {
|
47
|
+
var r = ranges[i];
|
48
|
+
if (_grid.canCellBeSelected(r.fromRow, r.fromCell) && _grid.canCellBeSelected(r.toRow, r.toCell)) {
|
49
|
+
result.push(r);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
return result;
|
54
|
+
}
|
55
|
+
|
56
|
+
function setSelectedRanges(ranges) {
|
57
|
+
_ranges = removeInvalidRanges(ranges);
|
58
|
+
_self.onSelectedRangesChanged.notify(_ranges);
|
59
|
+
}
|
60
|
+
|
61
|
+
function getSelectedRanges() {
|
62
|
+
return _ranges;
|
63
|
+
}
|
64
|
+
|
65
|
+
function handleBeforeCellRangeSelected(e, args) {
|
66
|
+
if (_grid.getEditorLock().isActive()) {
|
67
|
+
e.stopPropagation();
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
function handleCellRangeSelected(e, args) {
|
73
|
+
setSelectedRanges([args.range]);
|
74
|
+
}
|
75
|
+
|
76
|
+
function handleActiveCellChange(e, args) {
|
77
|
+
if (_options.selectActiveCell) {
|
78
|
+
setSelectedRanges([new Slick.Range(args.row, args.cell)]);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
$.extend(this, {
|
83
|
+
"getSelectedRanges": getSelectedRanges,
|
84
|
+
"setSelectedRanges": setSelectedRanges,
|
85
|
+
|
86
|
+
"init": init,
|
87
|
+
"destroy": destroy,
|
88
|
+
|
89
|
+
"onSelectedRangesChanged": new Slick.Event()
|
90
|
+
});
|
91
|
+
}
|
92
|
+
})(jQuery);
|
@@ -0,0 +1,154 @@
|
|
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 _selectedRowsLookup = {};
|
14
|
+
var _defaults = {
|
15
|
+
columnId: "_checkbox_selector",
|
16
|
+
cssClass: null,
|
17
|
+
toolTip: "Select/Deselect All",
|
18
|
+
width: 30
|
19
|
+
};
|
20
|
+
|
21
|
+
var _options = $.extend(true, {}, _defaults, options);
|
22
|
+
|
23
|
+
function init(grid) {
|
24
|
+
_grid = grid;
|
25
|
+
_grid.onSelectedRowsChanged.subscribe(handleSelectedRowsChanged);
|
26
|
+
_grid.onClick.subscribe(handleClick);
|
27
|
+
_grid.onHeaderClick.subscribe(handleHeaderClick);
|
28
|
+
_grid.onKeyDown.subscribe(handleKeyDown);
|
29
|
+
}
|
30
|
+
|
31
|
+
function destroy() {
|
32
|
+
_grid.onSelectedRowsChanged.unsubscribe(handleSelectedRowsChanged);
|
33
|
+
_grid.onClick.unsubscribe(handleClick);
|
34
|
+
_grid.onHeaderClick.unsubscribe(handleHeaderClick);
|
35
|
+
_grid.onKeyDown.unsubscribe(handleKeyDown);
|
36
|
+
}
|
37
|
+
|
38
|
+
function handleSelectedRowsChanged(e, args) {
|
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 == _grid.getDataLength()) {
|
56
|
+
_grid.updateColumnHeader(_options.columnId, "<input type='checkbox' checked='checked'>", _options.toolTip);
|
57
|
+
} else {
|
58
|
+
_grid.updateColumnHeader(_options.columnId, "<input type='checkbox'>", _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
|
+
}
|
100
|
+
|
101
|
+
function handleHeaderClick(e, args) {
|
102
|
+
if (args.column.id == _options.columnId && $(e.target).is(":checkbox")) {
|
103
|
+
// if editing, try to commit
|
104
|
+
if (_grid.getEditorLock().isActive() && !_grid.getEditorLock().commitCurrentEdit()) {
|
105
|
+
e.preventDefault();
|
106
|
+
e.stopImmediatePropagation();
|
107
|
+
return;
|
108
|
+
}
|
109
|
+
|
110
|
+
if ($(e.target).is(":checked")) {
|
111
|
+
var rows = [];
|
112
|
+
for (var i = 0; i < _grid.getDataLength(); i++) {
|
113
|
+
rows.push(i);
|
114
|
+
}
|
115
|
+
_grid.setSelectedRows(rows);
|
116
|
+
} else {
|
117
|
+
_grid.setSelectedRows([]);
|
118
|
+
}
|
119
|
+
e.stopPropagation();
|
120
|
+
e.stopImmediatePropagation();
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
function getColumnDefinition() {
|
125
|
+
return {
|
126
|
+
id: _options.columnId,
|
127
|
+
name: "<input type='checkbox'>",
|
128
|
+
toolTip: _options.toolTip,
|
129
|
+
field: "sel",
|
130
|
+
width: _options.width,
|
131
|
+
resizable: false,
|
132
|
+
sortable: false,
|
133
|
+
cssClass: _options.cssClass,
|
134
|
+
formatter: checkboxSelectionFormatter
|
135
|
+
};
|
136
|
+
}
|
137
|
+
|
138
|
+
function checkboxSelectionFormatter(row, cell, value, columnDef, dataContext) {
|
139
|
+
if (dataContext) {
|
140
|
+
return _selectedRowsLookup[row]
|
141
|
+
? "<input type='checkbox' checked='checked'>"
|
142
|
+
: "<input type='checkbox'>";
|
143
|
+
}
|
144
|
+
return null;
|
145
|
+
}
|
146
|
+
|
147
|
+
$.extend(this, {
|
148
|
+
"init": init,
|
149
|
+
"destroy": destroy,
|
150
|
+
|
151
|
+
"getColumnDefinition": getColumnDefinition
|
152
|
+
});
|
153
|
+
}
|
154
|
+
})(jQuery);
|
@@ -0,0 +1,132 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"RowMoveManager": RowMoveManager
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function RowMoveManager() {
|
10
|
+
var _grid;
|
11
|
+
var _canvas;
|
12
|
+
var _dragging;
|
13
|
+
var _self = this;
|
14
|
+
|
15
|
+
function init(grid) {
|
16
|
+
_grid = grid;
|
17
|
+
_canvas = _grid.getCanvasNode();
|
18
|
+
_grid.onDragInit.subscribe(handleDragInit);
|
19
|
+
_grid.onDragStart.subscribe(handleDragStart);
|
20
|
+
_grid.onDrag.subscribe(handleDrag);
|
21
|
+
_grid.onDragEnd.subscribe(handleDragEnd);
|
22
|
+
}
|
23
|
+
|
24
|
+
function destroy() {
|
25
|
+
_grid.onDragInit.unsubscribe(handleDragInit);
|
26
|
+
_grid.onDragStart.unsubscribe(handleDragStart);
|
27
|
+
_grid.onDrag.unsubscribe(handleDrag);
|
28
|
+
_grid.onDragEnd.unsubscribe(handleDragEnd);
|
29
|
+
}
|
30
|
+
|
31
|
+
function handleDragInit(e, dd) {
|
32
|
+
// prevent the grid from cancelling drag'n'drop by default
|
33
|
+
e.stopImmediatePropagation();
|
34
|
+
}
|
35
|
+
|
36
|
+
function handleDragStart(e, dd) {
|
37
|
+
var cell = _grid.getCellFromEvent(e);
|
38
|
+
if (_grid.getEditorLock().isActive() || !/move|selectAndMove/.test(_grid.getColumns()[cell.cell].behavior)) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
|
42
|
+
_dragging = true;
|
43
|
+
e.stopImmediatePropagation();
|
44
|
+
|
45
|
+
var selectedRows = _grid.getSelectedRows();
|
46
|
+
|
47
|
+
if (selectedRows.length == 0 || $.inArray(cell.row, selectedRows) == -1) {
|
48
|
+
selectedRows = [cell.row];
|
49
|
+
_grid.setSelectedRows(selectedRows);
|
50
|
+
}
|
51
|
+
|
52
|
+
var rowHeight = _grid.getOptions().rowHeight;
|
53
|
+
|
54
|
+
dd.selectedRows = selectedRows;
|
55
|
+
|
56
|
+
dd.selectionProxy = $("<div class='slick-reorder-proxy'/>")
|
57
|
+
.css("position", "absolute")
|
58
|
+
.css("zIndex", "99999")
|
59
|
+
.css("width", $(_canvas).innerWidth())
|
60
|
+
.css("height", rowHeight * selectedRows.length)
|
61
|
+
.appendTo(_canvas);
|
62
|
+
|
63
|
+
dd.guide = $("<div class='slick-reorder-guide'/>")
|
64
|
+
.css("position", "absolute")
|
65
|
+
.css("zIndex", "99998")
|
66
|
+
.css("width", $(_canvas).innerWidth())
|
67
|
+
.css("top", -1000)
|
68
|
+
.appendTo(_canvas);
|
69
|
+
|
70
|
+
dd.insertBefore = -1;
|
71
|
+
|
72
|
+
return $("<div></div>").appendTo(_canvas);
|
73
|
+
}
|
74
|
+
|
75
|
+
function handleDrag(e, dd) {
|
76
|
+
if (!_dragging) {
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
e.stopImmediatePropagation();
|
81
|
+
|
82
|
+
var top = e.pageY - $(_canvas).offset().top;
|
83
|
+
dd.selectionProxy.css("top", top - 5);
|
84
|
+
|
85
|
+
var insertBefore = Math.max(0, Math.min(Math.round(top / _grid.getOptions().rowHeight), _grid.getDataLength()));
|
86
|
+
if (insertBefore !== dd.insertBefore) {
|
87
|
+
var eventData = {
|
88
|
+
"rows": dd.selectedRows,
|
89
|
+
"insertBefore": insertBefore
|
90
|
+
};
|
91
|
+
|
92
|
+
if (_self.onBeforeMoveRows.notify(eventData) === false) {
|
93
|
+
dd.guide.css("top", -1000);
|
94
|
+
dd.canMove = false;
|
95
|
+
} else {
|
96
|
+
dd.guide.css("top", insertBefore * _grid.getOptions().rowHeight);
|
97
|
+
dd.canMove = true;
|
98
|
+
}
|
99
|
+
|
100
|
+
dd.insertBefore = insertBefore;
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
function handleDragEnd(e, dd) {
|
105
|
+
if (!_dragging) {
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
_dragging = false;
|
109
|
+
e.stopImmediatePropagation();
|
110
|
+
|
111
|
+
dd.guide.remove();
|
112
|
+
dd.selectionProxy.remove();
|
113
|
+
|
114
|
+
if (dd.canMove) {
|
115
|
+
var eventData = {
|
116
|
+
"rows": dd.selectedRows,
|
117
|
+
"insertBefore": dd.insertBefore
|
118
|
+
};
|
119
|
+
// TODO: _grid.remapCellCssClasses ?
|
120
|
+
_self.onMoveRows.notify(eventData);
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
$.extend(this, {
|
125
|
+
"onBeforeMoveRows": new Slick.Event(),
|
126
|
+
"onMoveRows": new Slick.Event(),
|
127
|
+
|
128
|
+
"init": init,
|
129
|
+
"destroy": destroy
|
130
|
+
});
|
131
|
+
}
|
132
|
+
})(jQuery);
|
@@ -0,0 +1,187 @@
|
|
1
|
+
(function ($) {
|
2
|
+
// register namespace
|
3
|
+
$.extend(true, window, {
|
4
|
+
"Slick": {
|
5
|
+
"RowSelectionModel": RowSelectionModel
|
6
|
+
}
|
7
|
+
});
|
8
|
+
|
9
|
+
function RowSelectionModel(options) {
|
10
|
+
var _grid;
|
11
|
+
var _ranges = [];
|
12
|
+
var _self = this;
|
13
|
+
var _handler = new Slick.EventHandler();
|
14
|
+
var _inHandler;
|
15
|
+
var _options;
|
16
|
+
var _defaults = {
|
17
|
+
selectActiveRow: true
|
18
|
+
};
|
19
|
+
|
20
|
+
function init(grid) {
|
21
|
+
_options = $.extend(true, {}, _defaults, options);
|
22
|
+
_grid = grid;
|
23
|
+
_handler.subscribe(_grid.onActiveCellChanged,
|
24
|
+
wrapHandler(handleActiveCellChange));
|
25
|
+
_handler.subscribe(_grid.onKeyDown,
|
26
|
+
wrapHandler(handleKeyDown));
|
27
|
+
_handler.subscribe(_grid.onClick,
|
28
|
+
wrapHandler(handleClick));
|
29
|
+
}
|
30
|
+
|
31
|
+
function destroy() {
|
32
|
+
_handler.unsubscribeAll();
|
33
|
+
}
|
34
|
+
|
35
|
+
function wrapHandler(handler) {
|
36
|
+
return function () {
|
37
|
+
if (!_inHandler) {
|
38
|
+
_inHandler = true;
|
39
|
+
handler.apply(this, arguments);
|
40
|
+
_inHandler = false;
|
41
|
+
}
|
42
|
+
};
|
43
|
+
}
|
44
|
+
|
45
|
+
function rangesToRows(ranges) {
|
46
|
+
var rows = [];
|
47
|
+
for (var i = 0; i < ranges.length; i++) {
|
48
|
+
for (var j = ranges[i].fromRow; j <= ranges[i].toRow; j++) {
|
49
|
+
rows.push(j);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
return rows;
|
53
|
+
}
|
54
|
+
|
55
|
+
function rowsToRanges(rows) {
|
56
|
+
var ranges = [];
|
57
|
+
var lastCell = _grid.getColumns().length - 1;
|
58
|
+
for (var i = 0; i < rows.length; i++) {
|
59
|
+
ranges.push(new Slick.Range(rows[i], 0, rows[i], lastCell));
|
60
|
+
}
|
61
|
+
return ranges;
|
62
|
+
}
|
63
|
+
|
64
|
+
function getRowsRange(from, to) {
|
65
|
+
var i, rows = [];
|
66
|
+
for (i = from; i <= to; i++) {
|
67
|
+
rows.push(i);
|
68
|
+
}
|
69
|
+
for (i = to; i < from; i++) {
|
70
|
+
rows.push(i);
|
71
|
+
}
|
72
|
+
return rows;
|
73
|
+
}
|
74
|
+
|
75
|
+
function getSelectedRows() {
|
76
|
+
return rangesToRows(_ranges);
|
77
|
+
}
|
78
|
+
|
79
|
+
function setSelectedRows(rows) {
|
80
|
+
setSelectedRanges(rowsToRanges(rows));
|
81
|
+
}
|
82
|
+
|
83
|
+
function setSelectedRanges(ranges) {
|
84
|
+
_ranges = ranges;
|
85
|
+
_self.onSelectedRangesChanged.notify(_ranges);
|
86
|
+
}
|
87
|
+
|
88
|
+
function getSelectedRanges() {
|
89
|
+
return _ranges;
|
90
|
+
}
|
91
|
+
|
92
|
+
function handleActiveCellChange(e, data) {
|
93
|
+
if (_options.selectActiveRow) {
|
94
|
+
setSelectedRanges([new Slick.Range(data.row, 0, data.row, _grid.getColumns().length - 1)]);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
function handleKeyDown(e) {
|
99
|
+
var activeRow = _grid.getActiveCell();
|
100
|
+
if (activeRow && e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey && (e.which == 38 || e.which == 40)) {
|
101
|
+
var selectedRows = getSelectedRows();
|
102
|
+
selectedRows.sort(function (x, y) {
|
103
|
+
return x - y
|
104
|
+
});
|
105
|
+
|
106
|
+
if (!selectedRows.length) {
|
107
|
+
selectedRows = [activeRow.row];
|
108
|
+
}
|
109
|
+
|
110
|
+
var top = selectedRows[0];
|
111
|
+
var bottom = selectedRows[selectedRows.length - 1];
|
112
|
+
var active;
|
113
|
+
|
114
|
+
if (e.which == 40) {
|
115
|
+
active = activeRow.row < bottom || top == bottom ? ++bottom : ++top;
|
116
|
+
} else {
|
117
|
+
active = activeRow.row < bottom ? --bottom : --top;
|
118
|
+
}
|
119
|
+
|
120
|
+
if (active >= 0 && active < _grid.getDataLength()) {
|
121
|
+
_grid.scrollRowIntoView(active);
|
122
|
+
_ranges = rowsToRanges(getRowsRange(top, bottom));
|
123
|
+
setSelectedRanges(_ranges);
|
124
|
+
}
|
125
|
+
|
126
|
+
e.preventDefault();
|
127
|
+
e.stopPropagation();
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
function handleClick(e) {
|
132
|
+
var cell = _grid.getCellFromEvent(e);
|
133
|
+
if (!cell || !_grid.canCellBeActive(cell.row, cell.cell)) {
|
134
|
+
return false;
|
135
|
+
}
|
136
|
+
|
137
|
+
var selection = rangesToRows(_ranges);
|
138
|
+
var idx = $.inArray(cell.row, selection);
|
139
|
+
|
140
|
+
if (!e.ctrlKey && !e.shiftKey && !e.metaKey) {
|
141
|
+
return false;
|
142
|
+
}
|
143
|
+
else if (_grid.getOptions().multiSelect) {
|
144
|
+
if (idx === -1 && (e.ctrlKey || e.metaKey)) {
|
145
|
+
selection.push(cell.row);
|
146
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
147
|
+
} else if (idx !== -1 && (e.ctrlKey || e.metaKey)) {
|
148
|
+
selection = $.grep(selection, function (o, i) {
|
149
|
+
return (o !== cell.row);
|
150
|
+
});
|
151
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
152
|
+
} else if (selection.length && e.shiftKey) {
|
153
|
+
var last = selection.pop();
|
154
|
+
var from = Math.min(cell.row, last);
|
155
|
+
var to = Math.max(cell.row, last);
|
156
|
+
selection = [];
|
157
|
+
for (var i = from; i <= to; i++) {
|
158
|
+
if (i !== last) {
|
159
|
+
selection.push(i);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
selection.push(last);
|
163
|
+
_grid.setActiveCell(cell.row, cell.cell);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
_ranges = rowsToRanges(selection);
|
168
|
+
setSelectedRanges(_ranges);
|
169
|
+
e.stopImmediatePropagation();
|
170
|
+
|
171
|
+
return true;
|
172
|
+
}
|
173
|
+
|
174
|
+
$.extend(this, {
|
175
|
+
"getSelectedRows": getSelectedRows,
|
176
|
+
"setSelectedRows": setSelectedRows,
|
177
|
+
|
178
|
+
"getSelectedRanges": getSelectedRanges,
|
179
|
+
"setSelectedRanges": setSelectedRanges,
|
180
|
+
|
181
|
+
"init": init,
|
182
|
+
"destroy": destroy,
|
183
|
+
|
184
|
+
"onSelectedRangesChanged": new Slick.Event()
|
185
|
+
});
|
186
|
+
}
|
187
|
+
})(jQuery);
|