Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 66 additions & 20 deletions src/features/move-columns/js/column-movable.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,45 +369,91 @@
}
}

var targetIndex;

//Case where column should be moved to a position on its left
if (totalMouseMovement < 0) {
var totalColumnsLeftWidth = 0;
for (var il = columnIndex - 1; il >= 0; il--) {
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, il + 1);
break;
var il;
if ( $scope.grid.isRTL() ){
for (il = columnIndex + 1; il < columns.length; il++) {
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, il - 1);
break;
}
}
}
}
//Case where column should be moved to beginning of the grid.
else {
for (il = columnIndex - 1; il >= 0; il--) {
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, il + 1);
break;
}
}
}
}

//Case where column should be moved to beginning (or end in RTL) of the grid.
if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) {
targetIndex = 0;
if ( $scope.grid.isRTL() ){
targetIndex = columns.length - 1;
}
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, 0);
($scope.grid, columnIndex, targetIndex);
}
}

//Case where column should be moved to a position on its right
else if (totalMouseMovement > 0) {
var totalColumnsRightWidth = 0;
for (var ir = columnIndex + 1; ir < columns.length; ir++) {
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
if (totalColumnsRightWidth > totalMouseMovement) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, ir - 1);
break;
var ir;
if ( $scope.grid.isRTL() ){
for (ir = columnIndex - 1; ir > 0; ir--) {
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
if (totalColumnsRightWidth > totalMouseMovement) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, ir);
break;
}
}
}
}
else {
for (ir = columnIndex + 1; ir < columns.length; ir++) {
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
if (totalColumnsRightWidth > totalMouseMovement) {
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, ir - 1);
break;
}
}
}
}
//Case where column should be moved to end of the grid.


//Case where column should be moved to end (or beginning in RTL) of the grid.
if (totalColumnsRightWidth < totalMouseMovement) {
targetIndex = columns.length - 1;
if ( $scope.grid.isRTL() ){
targetIndex = 0;
}
uiGridMoveColumnService.redrawColumnAtPosition
($scope.grid, columnIndex, columns.length - 1);
($scope.grid, columnIndex, targetIndex);
}
}



};

var onDownEvents = function(){
Expand Down Expand Up @@ -469,8 +515,8 @@

//Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid
if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) {
movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft +
(newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'});
movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft +
(newElementLeft < rightMoveLimit ? changeValue : (rightMoveLimit - currentElmLeft))) + 'px'});
}
else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) {
changeValue *= 8;
Expand Down