Skip to content

Commit 84e9a37

Browse files
committed
fix reversed column moving direction in RTL
1 parent 4e9e0cf commit 84e9a37

File tree

1 file changed

+66
-20
lines changed

1 file changed

+66
-20
lines changed

src/features/move-columns/js/column-movable.js

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -369,45 +369,91 @@
369369
}
370370
}
371371

372+
var targetIndex;
373+
372374
//Case where column should be moved to a position on its left
373375
if (totalMouseMovement < 0) {
374376
var totalColumnsLeftWidth = 0;
375-
for (var il = columnIndex - 1; il >= 0; il--) {
376-
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
377-
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
378-
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
379-
uiGridMoveColumnService.redrawColumnAtPosition
380-
($scope.grid, columnIndex, il + 1);
381-
break;
377+
var il;
378+
if ( $scope.grid.isRTL() ){
379+
for (il = columnIndex + 1; il < columns.length; il++) {
380+
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
381+
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
382+
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
383+
uiGridMoveColumnService.redrawColumnAtPosition
384+
($scope.grid, columnIndex, il - 1);
385+
break;
386+
}
382387
}
383388
}
384389
}
385-
//Case where column should be moved to beginning of the grid.
390+
else {
391+
for (il = columnIndex - 1; il >= 0; il--) {
392+
if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) {
393+
totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width;
394+
if (totalColumnsLeftWidth > Math.abs(totalMouseMovement)) {
395+
uiGridMoveColumnService.redrawColumnAtPosition
396+
($scope.grid, columnIndex, il + 1);
397+
break;
398+
}
399+
}
400+
}
401+
}
402+
403+
//Case where column should be moved to beginning (or end in RTL) of the grid.
386404
if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) {
405+
targetIndex = 0;
406+
if ( $scope.grid.isRTL() ){
407+
targetIndex = columns.length - 1;
408+
}
387409
uiGridMoveColumnService.redrawColumnAtPosition
388-
($scope.grid, columnIndex, 0);
410+
($scope.grid, columnIndex, targetIndex);
389411
}
390412
}
391413

392414
//Case where column should be moved to a position on its right
393415
else if (totalMouseMovement > 0) {
394416
var totalColumnsRightWidth = 0;
395-
for (var ir = columnIndex + 1; ir < columns.length; ir++) {
396-
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
397-
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
398-
if (totalColumnsRightWidth > totalMouseMovement) {
399-
uiGridMoveColumnService.redrawColumnAtPosition
400-
($scope.grid, columnIndex, ir - 1);
401-
break;
417+
var ir;
418+
if ( $scope.grid.isRTL() ){
419+
for (ir = columnIndex - 1; ir > 0; ir--) {
420+
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
421+
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
422+
if (totalColumnsRightWidth > totalMouseMovement) {
423+
uiGridMoveColumnService.redrawColumnAtPosition
424+
($scope.grid, columnIndex, ir);
425+
break;
426+
}
427+
}
428+
}
429+
}
430+
else {
431+
for (ir = columnIndex + 1; ir < columns.length; ir++) {
432+
if (angular.isUndefined(columns[ir].colDef.visible) || columns[ir].colDef.visible === true) {
433+
totalColumnsRightWidth += columns[ir].drawnWidth || columns[ir].width || columns[ir].colDef.width;
434+
if (totalColumnsRightWidth > totalMouseMovement) {
435+
uiGridMoveColumnService.redrawColumnAtPosition
436+
($scope.grid, columnIndex, ir - 1);
437+
break;
438+
}
402439
}
403440
}
404441
}
405-
//Case where column should be moved to end of the grid.
442+
443+
444+
//Case where column should be moved to end (or beginning in RTL) of the grid.
406445
if (totalColumnsRightWidth < totalMouseMovement) {
446+
targetIndex = columns.length - 1;
447+
if ( $scope.grid.isRTL() ){
448+
targetIndex = 0;
449+
}
407450
uiGridMoveColumnService.redrawColumnAtPosition
408-
($scope.grid, columnIndex, columns.length - 1);
451+
($scope.grid, columnIndex, targetIndex);
409452
}
410453
}
454+
455+
456+
411457
};
412458

413459
var onDownEvents = function(){
@@ -469,8 +515,8 @@
469515

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

0 commit comments

Comments
 (0)