Skip to content

Commit

Permalink
Merge pull request #60 from GenesysPureConnect/move-cols-keyboard
Browse files Browse the repository at this point in the history
fix: allow moving columns via keyboard shortcuts
  • Loading branch information
stormojm authored May 23, 2019
2 parents 0767b38 + 059f6fd commit 145e7e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/features/move-columns/js/column-movable.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
$timeout(function () {
grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN );
grid.api.colMovable.raise.columnPositionChanged(originalColumn.colDef, originalPosition, newPosition);
var selector = '.ui-grid-header-cell.ui-grid-col' + originalColumn.uid + ' .ui-grid-cell-contents'
angular.element(selector).focus();
});
}
};
Expand Down
22 changes: 22 additions & 0 deletions src/js/core/directives/ui-grid-header-cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,24 @@
}).catch(angular.noop);
}

function applyMoveColumn(moveRight) {
if (!$scope.col) { return; }
if (!uiGridCtrl.grid.api.colMovable) { return; }

var columns = $scope.grid.columns;
var columnIndex = 0;
for (var i = 0; i < columns.length; i++) {
if (columns[i].colDef.name === $scope.col.colDef.name) {
columnIndex = i;
break;
}
}

// Move Column already handles checking valid index ranges.
var newIndex = moveRight ? columnIndex + 1 : columnIndex - 1;
uiGridCtrl.grid.api.colMovable.moveColumn(columnIndex, newIndex);
}

$scope.handleClick = function(event) {
// If the shift key is being held down, add this column to the sort
applySort(event.shiftKey);
Expand All @@ -356,6 +374,10 @@
$scope.handleKeyDown = function(event) {
if (event.key === 'Enter' || event.key === ' ') {
applySort(event.shiftKey);
} else if (event.altKey && event.key === "ArrowLeft") {
applyMoveColumn(false);
} else if (event.altKey && event.key === "ArrowRight") {
applyMoveColumn(true);
}
};

Expand Down

0 comments on commit 145e7e5

Please sign in to comment.