|
369 | 369 | }
|
370 | 370 | }
|
371 | 371 |
|
| 372 | + var targetIndex; |
| 373 | + |
372 | 374 | //Case where column should be moved to a position on its left
|
373 | 375 | if (totalMouseMovement < 0) {
|
374 | 376 | 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 | + } |
382 | 387 | }
|
383 | 388 | }
|
384 | 389 | }
|
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. |
386 | 404 | if (totalColumnsLeftWidth < Math.abs(totalMouseMovement)) {
|
| 405 | + targetIndex = 0; |
| 406 | + if ( $scope.grid.isRTL() ){ |
| 407 | + targetIndex = columns.length - 1; |
| 408 | + } |
387 | 409 | uiGridMoveColumnService.redrawColumnAtPosition
|
388 |
| - ($scope.grid, columnIndex, 0); |
| 410 | + ($scope.grid, columnIndex, targetIndex); |
389 | 411 | }
|
390 | 412 | }
|
391 | 413 |
|
392 | 414 | //Case where column should be moved to a position on its right
|
393 | 415 | else if (totalMouseMovement > 0) {
|
394 | 416 | 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 | + } |
402 | 439 | }
|
403 | 440 | }
|
404 | 441 | }
|
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. |
406 | 445 | if (totalColumnsRightWidth < totalMouseMovement) {
|
| 446 | + targetIndex = columns.length - 1; |
| 447 | + if ( $scope.grid.isRTL() ){ |
| 448 | + targetIndex = 0; |
| 449 | + } |
407 | 450 | uiGridMoveColumnService.redrawColumnAtPosition
|
408 |
| - ($scope.grid, columnIndex, columns.length - 1); |
| 451 | + ($scope.grid, columnIndex, targetIndex); |
409 | 452 | }
|
410 | 453 | }
|
| 454 | + |
| 455 | + |
| 456 | + |
411 | 457 | };
|
412 | 458 |
|
413 | 459 | var onDownEvents = function(){
|
|
469 | 515 |
|
470 | 516 | //Update css of moving column to adjust to new left value or fire scroll in case column has reached edge of grid
|
471 | 517 | 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'}); |
474 | 520 | }
|
475 | 521 | else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) {
|
476 | 522 | changeValue *= 8;
|
|
0 commit comments