Skip to content
Browse files

Added spacebar handling to CheckboxSelectColumn plugin (issue #277).

  • Loading branch information...
1 parent 0d05279 commit d2839d38c7ca9dbf456ff25d5f3ac6d4feed0e65 @mleibman mleibman committed Feb 5, 2012
Showing with 27 additions and 8 deletions.
  1. +26 −7 plugins/slick.checkboxselectcolumn.js
  2. +1 −1 slick.grid.js
View
33 plugins/slick.checkboxselectcolumn.js
@@ -25,12 +25,14 @@
_grid.onSelectedRowsChanged.subscribe(handleSelectedRowsChanged);
_grid.onClick.subscribe(handleClick);
_grid.onHeaderClick.subscribe(handleHeaderClick);
+ _grid.onKeyDown.subscribe(handleKeyDown);
}
function destroy() {
_grid.onSelectedRowsChanged.unsubscribe(handleSelectedRowsChanged);
_grid.onClick.unsubscribe(handleClick);
_grid.onHeaderClick.unsubscribe(handleHeaderClick);
+ _grid.onKeyDown.unsubscribe(handleKeyDown);
}
function handleSelectedRowsChanged(e, args) {
@@ -57,6 +59,19 @@
}
}
+ function handleKeyDown(e, args) {
+ if (e.which == 32) {
+ if (_grid.getColumns()[args.cell].id === _options.columnId) {
+ // if editing, try to commit
+ if (!_grid.getEditorLock().isActive() || _grid.getEditorLock().commitCurrentEdit()) {
+ toggleRowSelection(args.row);
+ }
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ }
+ }
+ }
+
function handleClick(e, args) {
// clicking on a row select checkbox
if (_grid.getColumns()[args.cell].id === _options.columnId && $(e.target).is(":checkbox")) {
@@ -67,18 +82,22 @@
return;
}
- if (_selectedRowsLookup[args.row]) {
- _grid.setSelectedRows($.grep(_grid.getSelectedRows(), function (n) {
- return n != args.row
- }));
- } else {
- _grid.setSelectedRows(_grid.getSelectedRows().concat(args.row));
- }
+ toggleRowSelection(args.row);
e.stopPropagation();
e.stopImmediatePropagation();
}
}
+ function toggleRowSelection(row) {
+ if (_selectedRowsLookup[row]) {
+ _grid.setSelectedRows($.grep(_grid.getSelectedRows(), function (n) {
+ return n != row
+ }));
+ } else {
+ _grid.setSelectedRows(_grid.getSelectedRows().concat(row));
+ }
+ }
+
function handleHeaderClick(e, args) {
if (args.column.id == _options.columnId && $(e.target).is(":checkbox")) {
// if editing, try to commit
View
2 slick.grid.js
@@ -1673,7 +1673,7 @@ if (typeof Slick === "undefined") {
}
function handleKeyDown(e) {
- trigger(self.onKeyDown, {}, e);
+ trigger(self.onKeyDown, {row: activeRow, cell: activeCell}, e);
var handled = e.isImmediatePropagationStopped();
if (!handled) {

0 comments on commit d2839d3

Please sign in to comment.
Something went wrong with that request. Please try again.