Skip to content

Commit

Permalink
Fixed issue #520. Added flag for when user changed column widths.
Browse files Browse the repository at this point in the history
Now if user changes column widths, *s and percentages will not be taken
into account so column widths stay the same when grid data is being
updated.
  • Loading branch information
jonricaurte committed Jul 1, 2013
1 parent 4338ef6 commit 8101c46
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions build/ng-grid.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/30/2013 21:00
* Compiled At: 06/30/2013 22:01
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -826,7 +826,7 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
}
};
self.gripOnMouseDown = function(event) {
domUtilityService.isColumnResizing = true;
$scope.isColumnResizing = true;
if (event.ctrlKey && !self.pinned) {
self.toggleVisible();
domUtilityService.BuildStyles($scope, grid);
Expand All @@ -843,16 +843,16 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
$scope.hasUserChangedGridColumnWidths = true;
domUtilityService.BuildStyles($scope, grid);
return false;
};
self.gripOnMouseUp = function (event) {
$(document).off('mousemove', self.onMouseMove);
$(document).off('mouseup', self.gripOnMouseUp);
event.target.parentElement.style.cursor = 'default';
$scope.adjustScrollLeft(0);
domUtilityService.digest($scope);
domUtilityService.isColumnResizing = false;
$scope.isColumnResizing = false;
return false;
};
self.copy = function() {
Expand Down Expand Up @@ -1646,7 +1646,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
}

// check if it is a number
if (isNaN(t)) {
if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
t = colDef.width;
// figure out if the width is defined or if we need to calculate it
if (t === 'auto') { // set it for now until we have data and subscribe when it changes so we can set the width.
Expand Down Expand Up @@ -1769,7 +1769,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
if(!domUtilityService.isColumnResizing){
if(!$scope.isColumnResizing){
domUtilityService.RebuildGrid($scope, self);
}
$scope.$emit('ngGridEventColumns', a);
Expand Down
12 changes: 6 additions & 6 deletions build/ng-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/30/2013 21:00
* Compiled At: 06/30/2013 22:01
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -769,7 +769,7 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
}
};
self.gripOnMouseDown = function(event) {
domUtilityService.isColumnResizing = true;
$scope.isColumnResizing = true;
if (event.ctrlKey && !self.pinned) {
self.toggleVisible();
domUtilityService.BuildStyles($scope, grid);
Expand All @@ -786,16 +786,16 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
$scope.hasUserChangedGridColumnWidths = true;
domUtilityService.BuildStyles($scope, grid);
return false;
};
self.gripOnMouseUp = function (event) {
$(document).off('mousemove', self.onMouseMove);
$(document).off('mouseup', self.gripOnMouseUp);
event.target.parentElement.style.cursor = 'default';
$scope.adjustScrollLeft(0);
domUtilityService.digest($scope);
domUtilityService.isColumnResizing = false;
$scope.isColumnResizing = false;
return false;
};
self.copy = function() {
Expand Down Expand Up @@ -1411,7 +1411,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
isPercent = isNaN(colDef.width) ? $utils.endsWith(colDef.width, "%") : false;
t = isPercent ? colDef.width : parseInt(colDef.width, 10);
}
if (isNaN(t)) {
if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
t = colDef.width;
if (t === 'auto') {
ngColumn.width = ngColumn.minWidth;
Expand Down Expand Up @@ -1511,7 +1511,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
if(!domUtilityService.isColumnResizing){
if(!$scope.isColumnResizing){
domUtilityService.RebuildGrid($scope, self);
}
$scope.$emit('ngGridEventColumns', a);
Expand Down
4 changes: 2 additions & 2 deletions build/ng-grid.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions ng-grid-2.0.7.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* ng-grid JavaScript Library
* Authors: https://github.com/angular-ui/ng-grid/blob/master/README.md
* License: MIT (http://www.opensource.org/licenses/mit-license.php)
* Compiled At: 06/30/2013 21:00
* Compiled At: 06/30/2013 22:01
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -826,7 +826,7 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
}
};
self.gripOnMouseDown = function(event) {
domUtilityService.isColumnResizing = true;
$scope.isColumnResizing = true;
if (event.ctrlKey && !self.pinned) {
self.toggleVisible();
domUtilityService.BuildStyles($scope, grid);
Expand All @@ -843,16 +843,16 @@ var ngColumn = function (config, $scope, grid, domUtilityService, $templateCache
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
$scope.hasUserChangedGridColumnWidths = true;
domUtilityService.BuildStyles($scope, grid);
return false;
};
self.gripOnMouseUp = function (event) {
$(document).off('mousemove', self.onMouseMove);
$(document).off('mouseup', self.gripOnMouseUp);
event.target.parentElement.style.cursor = 'default';
$scope.adjustScrollLeft(0);
domUtilityService.digest($scope);
domUtilityService.isColumnResizing = false;
$scope.isColumnResizing = false;
return false;
};
self.copy = function() {
Expand Down Expand Up @@ -1646,7 +1646,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
}

// check if it is a number
if (isNaN(t)) {
if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
t = colDef.width;
// figure out if the width is defined or if we need to calculate it
if (t === 'auto') { // set it for now until we have data and subscribe when it changes so we can set the width.
Expand Down Expand Up @@ -1769,7 +1769,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
if(!domUtilityService.isColumnResizing){
if(!$scope.isColumnResizing){
domUtilityService.RebuildGrid($scope, self);
}
$scope.$emit('ngGridEventColumns', a);
Expand Down
4 changes: 2 additions & 2 deletions ng-grid-2.0.7.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/classes/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
}
};
self.gripOnMouseDown = function(event) {
domUtilityService.isColumnResizing = true;
$scope.isColumnResizing = true;
if (event.ctrlKey && !self.pinned) {
self.toggleVisible();
domUtilityService.BuildStyles($scope, grid);
Expand All @@ -137,16 +137,16 @@
var diff = event.clientX - self.startMousePosition;
var newWidth = diff + self.origWidth;
self.width = (newWidth < self.minWidth ? self.minWidth : (newWidth > self.maxWidth ? self.maxWidth : newWidth));
$scope.hasUserChangedGridColumnWidths = true;
domUtilityService.BuildStyles($scope, grid);
return false;
};
self.gripOnMouseUp = function (event) {
$(document).off('mousemove', self.onMouseMove);
$(document).off('mouseup', self.gripOnMouseUp);
event.target.parentElement.style.cursor = 'default';
$scope.adjustScrollLeft(0);
domUtilityService.digest($scope);
domUtilityService.isColumnResizing = false;
$scope.isColumnResizing = false;
return false;
};
self.copy = function() {
Expand Down
4 changes: 2 additions & 2 deletions src/classes/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
}

// check if it is a number
if (isNaN(t)) {
if (isNaN(t) && !$scope.hasUserChangedGridColumnWidths) {
t = colDef.width;
// figure out if the width is defined or if we need to calculate it
if (t === 'auto') { // set it for now until we have data and subscribe when it changes so we can set the width.
Expand Down Expand Up @@ -551,7 +551,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
if(!domUtilityService.isColumnResizing){
if(!$scope.isColumnResizing){
domUtilityService.RebuildGrid($scope, self);
}
$scope.$emit('ngGridEventColumns', a);
Expand Down

0 comments on commit 8101c46

Please sign in to comment.