|
291 | 291 | //Hide column menu
|
292 | 292 | uiGridCtrl.fireEvent('hide-menu');
|
293 | 293 |
|
| 294 | + //Calculate total column width |
| 295 | + var columns = $scope.grid.columns; |
| 296 | + var totalColumnWidth = 0; |
| 297 | + for (var i = 0; i < columns.length; i++) { |
| 298 | + if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) { |
| 299 | + totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width; |
| 300 | + } |
| 301 | + } |
| 302 | + |
294 | 303 | //Calculate new position of left of column
|
295 | 304 | var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1;
|
296 | 305 | var currentElmRight = movingElm[0].getBoundingClientRect().right;
|
|
307 | 316 | if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) {
|
308 | 317 | movingElm.css({visibility: 'visible', 'left': newElementLeft + 'px'});
|
309 | 318 | }
|
310 |
| - else { |
| 319 | + else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) { |
311 | 320 | changeValue *= 8;
|
312 | 321 | var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement');
|
313 | 322 | scrollEvent.x = {pixels: changeValue};
|
314 | 323 | scrollEvent.fireScrollingEvent();
|
315 | 324 | }
|
316 |
| - totalMouseMovement += changeValue; |
| 325 | + |
| 326 | + //Calculate total width of columns on the left of the moving column and the mouse movement |
| 327 | + var totalColumnsLeftWidth = 0; |
| 328 | + for (var il = 0; il < columns.length; il++) { |
| 329 | + if (angular.isUndefined(columns[il].colDef.visible) || columns[il].colDef.visible === true) { |
| 330 | + if (columns[il].colDef.name !== $scope.col.colDef.name) { |
| 331 | + totalColumnsLeftWidth += columns[il].drawnWidth || columns[il].width || columns[il].colDef.width; |
| 332 | + } |
| 333 | + else { |
| 334 | + break; |
| 335 | + } |
| 336 | + } |
| 337 | + } |
| 338 | + if ($scope.newScrollLeft === undefined) { |
| 339 | + totalMouseMovement += changeValue; |
| 340 | + } |
| 341 | + else { |
| 342 | + totalMouseMovement = $scope.newScrollLeft + newElementLeft - totalColumnsLeftWidth; |
| 343 | + } |
317 | 344 |
|
318 | 345 | //Increase width of moving column, in case the rightmost column was moved and its width was
|
319 | 346 | //decreased because of overflow
|
|
324 | 351 | };
|
325 | 352 |
|
326 | 353 | var mouseMoveHandler = function (evt) {
|
| 354 | + //Disable text selection in Chrome during column move |
| 355 | + document.onselectstart = function() { return false; }; |
| 356 | + |
327 | 357 | var changeValue = evt.pageX - previousMouseX;
|
328 | 358 | if (!elmCloned && Math.abs(changeValue) > 50) {
|
329 | 359 | cloneElement();
|
|
345 | 375 | $document.on('mousemove', mouseMoveHandler);
|
346 | 376 |
|
347 | 377 | var mouseUpHandler = function (evt) {
|
| 378 | + //Re-enable text selection after column move |
| 379 | + document.onselectstart = null; |
348 | 380 |
|
349 | 381 | //Remove the cloned element on mouse up.
|
350 | 382 | if (movingElm) {
|
|
0 commit comments