Skip to content

Commit

Permalink
When column changes, grid rebuilds instead of build styles.
Browse files Browse the repository at this point in the history
Fixed issue where if selection column was hidden, rows wouldn't take up
the remain space. Fixed issue where if columns were reordered, then one
was hidden, then reordered again, then made the one hidden visible,
columns would then be overlapping since the column indexes would be the
same.
  • Loading branch information
jonricaurte committed Jun 27, 2013
1 parent d7fb194 commit feab97e
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 54 deletions.
21 changes: 9 additions & 12 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/26/2013 19:28
* Compiled At: 06/27/2013 04:08
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -339,7 +339,7 @@ angular.module('ngGrid.services').factory('$domUtilityService',['$utilityService
domUtilityService.setColLeft.immediate = 1;
domUtilityService.RebuildGrid = function($scope, grid){
domUtilityService.UpdateGridLayout($scope, grid);
if (grid.config.maintainColumnRatios) {
if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
Expand Down Expand Up @@ -1121,10 +1121,9 @@ var ngEventProvider = function (grid, $scope, domUtilityService, $timeout) {
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
// Finally, rebuild the CSS styles.
domUtilityService.BuildStyles($scope, grid, true);
// clear out the colToMove object
self.colToMove = undefined;
domUtilityService.digest($scope);
}
};

Expand Down Expand Up @@ -1607,8 +1606,6 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
asteriskNum = 0,
totalWidth = 0;

totalWidth += self.config.showSelectionCheckbox ? 25 : 0;

// When rearranging columns, their index in $scope.columns will no longer match the original column order from columnDefs causing
// their width config to be out of sync. We can use "originalIndex" on the ngColumns to get hold of the correct setup from columnDefs, but to
// avoid O(n) lookups in $scope.columns per column we setup a map.
Expand All @@ -1619,6 +1616,10 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
var origIndex = ngCol.originalIndex;
if (self.config.showSelectionCheckbox) {
//if visible, takes up 25 pixels
if(i === 0 && ngCol.visible){
totalWidth += 25;
}
// The originalIndex will be offset 1 when including the selection column
origIndex--;
}
Expand Down Expand Up @@ -1765,7 +1766,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
domUtilityService.BuildStyles($scope, self, true);
domUtilityService.RebuildGrid($scope, self);
$scope.$emit('ngGridEventColumns', a);
}, true);
$scope.$watch(function() {
Expand Down Expand Up @@ -1908,9 +1909,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
self.fixColumnIndexes = function() {
//fix column indexes
for (var i = 0; i < $scope.columns.length; i++) {
if ($scope.columns[i].visible !== false) {
$scope.columns[i].index = i;
}
$scope.columns[i].index = i;
}
};
self.fixGroupIndexes = function() {
Expand Down Expand Up @@ -3014,9 +3013,7 @@ ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '
$scope.columns = [];
grid.config.columnDefs = a;
grid.buildColumns();
grid.configureColumnWidths();
grid.eventProvider.assignEvents();
domUtilityService.RebuildGrid($scope, grid);
}, true);
}
else {
Expand Down
19 changes: 8 additions & 11 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/26/2013 19:28
* Compiled At: 06/27/2013 04:08
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -318,7 +318,7 @@ angular.module('ngGrid.services').factory('$domUtilityService',['$utilityService
domUtilityService.setColLeft.immediate = 1;
domUtilityService.RebuildGrid = function($scope, grid){
domUtilityService.UpdateGridLayout($scope, grid);
if (grid.config.maintainColumnRatios) {
if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
Expand Down Expand Up @@ -1039,8 +1039,8 @@ var ngEventProvider = function (grid, $scope, domUtilityService, $timeout) {
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
domUtilityService.BuildStyles($scope, grid, true);
self.colToMove = undefined;
domUtilityService.digest($scope);
}
};

Expand Down Expand Up @@ -1384,13 +1384,14 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
percentArray = [],
asteriskNum = 0,
totalWidth = 0;

totalWidth += self.config.showSelectionCheckbox ? 25 : 0;
var indexMap = {};
angular.forEach($scope.columns, function(ngCol, i) {
if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
var origIndex = ngCol.originalIndex;
if (self.config.showSelectionCheckbox) {
if(i === 0 && ngCol.visible){
totalWidth += 25;
}
origIndex--;
}
indexMap[origIndex] = i;
Expand Down Expand Up @@ -1509,7 +1510,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
domUtilityService.BuildStyles($scope, self, true);
domUtilityService.RebuildGrid($scope, self);
$scope.$emit('ngGridEventColumns', a);
}, true);
$scope.$watch(function() {
Expand Down Expand Up @@ -1645,9 +1646,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
};
self.fixColumnIndexes = function() {
for (var i = 0; i < $scope.columns.length; i++) {
if ($scope.columns[i].visible !== false) {
$scope.columns[i].index = i;
}
$scope.columns[i].index = i;
}
};
self.fixGroupIndexes = function() {
Expand Down Expand Up @@ -2687,9 +2686,7 @@ ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '
$scope.columns = [];
grid.config.columnDefs = a;
grid.buildColumns();
grid.configureColumnWidths();
grid.eventProvider.assignEvents();
domUtilityService.RebuildGrid($scope, grid);
}, true);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions build/ng-grid.min.js

Large diffs are not rendered by default.

21 changes: 9 additions & 12 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/26/2013 19:28
* Compiled At: 06/27/2013 04:08
***********************************************/
(function(window, $) {
'use strict';
Expand Down Expand Up @@ -339,7 +339,7 @@ angular.module('ngGrid.services').factory('$domUtilityService',['$utilityService
domUtilityService.setColLeft.immediate = 1;
domUtilityService.RebuildGrid = function($scope, grid){
domUtilityService.UpdateGridLayout($scope, grid);
if (grid.config.maintainColumnRatios) {
if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
Expand Down Expand Up @@ -1121,10 +1121,9 @@ var ngEventProvider = function (grid, $scope, domUtilityService, $timeout) {
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
// Finally, rebuild the CSS styles.
domUtilityService.BuildStyles($scope, grid, true);
// clear out the colToMove object
self.colToMove = undefined;
domUtilityService.digest($scope);
}
};

Expand Down Expand Up @@ -1607,8 +1606,6 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
asteriskNum = 0,
totalWidth = 0;

totalWidth += self.config.showSelectionCheckbox ? 25 : 0;

// When rearranging columns, their index in $scope.columns will no longer match the original column order from columnDefs causing
// their width config to be out of sync. We can use "originalIndex" on the ngColumns to get hold of the correct setup from columnDefs, but to
// avoid O(n) lookups in $scope.columns per column we setup a map.
Expand All @@ -1619,6 +1616,10 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
var origIndex = ngCol.originalIndex;
if (self.config.showSelectionCheckbox) {
//if visible, takes up 25 pixels
if(i === 0 && ngCol.visible){
totalWidth += 25;
}
// The originalIndex will be offset 1 when including the selection column
origIndex--;
}
Expand Down Expand Up @@ -1765,7 +1766,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
domUtilityService.BuildStyles($scope, self, true);
domUtilityService.RebuildGrid($scope, self);
$scope.$emit('ngGridEventColumns', a);
}, true);
$scope.$watch(function() {
Expand Down Expand Up @@ -1908,9 +1909,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
self.fixColumnIndexes = function() {
//fix column indexes
for (var i = 0; i < $scope.columns.length; i++) {
if ($scope.columns[i].visible !== false) {
$scope.columns[i].index = i;
}
$scope.columns[i].index = i;
}
};
self.fixGroupIndexes = function() {
Expand Down Expand Up @@ -3014,9 +3013,7 @@ ngGridDirectives.directive('ngGrid', ['$compile', '$filter', '$templateCache', '
$scope.columns = [];
grid.config.columnDefs = a;
grid.buildColumns();
grid.configureColumnWidths();
grid.eventProvider.assignEvents();
domUtilityService.RebuildGrid($scope, grid);
}, true);
}
else {
Expand Down
4 changes: 2 additions & 2 deletions ng-grid-2.0.7.min.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions plugins/ng-grid-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ function ngGridLayoutPlugin () {
self.domUtilityService = services.DomUtilityService;
self.grid = grid;
self.scope = scope;

// Register for column rearranging events
scope.$parent.$on('ngGridEventColumns', self.updateGridLayout);
};

this.updateGridLayout = function () {
Expand Down
3 changes: 1 addition & 2 deletions src/classes/eventProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,9 @@
$scope.columns.splice(self.colToMove.col.index, 1);
$scope.columns.splice(headerScope.col.index, 0, self.colToMove.col);
grid.fixColumnIndexes();
// Finally, rebuild the CSS styles.
domUtilityService.BuildStyles($scope, grid, true);
// clear out the colToMove object
self.colToMove = undefined;
domUtilityService.digest($scope);
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/classes/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
asteriskNum = 0,
totalWidth = 0;

totalWidth += self.config.showSelectionCheckbox ? 25 : 0;

// When rearranging columns, their index in $scope.columns will no longer match the original column order from columnDefs causing
// their width config to be out of sync. We can use "originalIndex" on the ngColumns to get hold of the correct setup from columnDefs, but to
// avoid O(n) lookups in $scope.columns per column we setup a map.
Expand All @@ -395,6 +393,10 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
if (!$utils.isNullOrUndefined(ngCol.originalIndex)) {
var origIndex = ngCol.originalIndex;
if (self.config.showSelectionCheckbox) {
//if visible, takes up 25 pixels
if(i === 0 && ngCol.visible){
totalWidth += 25;
}
// The originalIndex will be offset 1 when including the selection column
origIndex--;
}
Expand Down Expand Up @@ -541,7 +543,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
$scope.$emit('ngGridEventGroups', a);
}, true);
$scope.$watch('columns', function (a) {
domUtilityService.BuildStyles($scope, self, true);
domUtilityService.RebuildGrid($scope, self);
$scope.$emit('ngGridEventColumns', a);
}, true);
$scope.$watch(function() {
Expand Down Expand Up @@ -684,9 +686,7 @@ var ngGrid = function ($scope, options, sortService, domUtilityService, $filter,
self.fixColumnIndexes = function() {
//fix column indexes
for (var i = 0; i < $scope.columns.length; i++) {
if ($scope.columns[i].visible !== false) {
$scope.columns[i].index = i;
}
$scope.columns[i].index = i;
}
};
self.fixGroupIndexes = function() {
Expand Down
2 changes: 0 additions & 2 deletions src/directives/ng-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
$scope.columns = [];
grid.config.columnDefs = a;
grid.buildColumns();
grid.configureColumnWidths();
grid.eventProvider.assignEvents();
domUtilityService.RebuildGrid($scope, grid);
}, true);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion src/services/DomUtilityService.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
domUtilityService.setColLeft.immediate = 1;
domUtilityService.RebuildGrid = function($scope, grid){
domUtilityService.UpdateGridLayout($scope, grid);
if (grid.config.maintainColumnRatios) {
if (grid.config.maintainColumnRatios == null || grid.config.maintainColumnRatios) {
grid.configureColumnWidths();
}
$scope.adjustScrollLeft(grid.$viewport.scrollLeft());
Expand Down
4 changes: 3 additions & 1 deletion workbench/main4.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function userController($scope) {
multiSelect: false,
enableRowReordering: false,
showGroupPanel: true,
columnDefs: 'myDefs'
columnDefs: 'myDefs',
showColumnMenu: true,
enableColumnReordering: true
};

$scope.myData = [{ 'Sku': 'C-2820164', 'Vendor': 'NEWB', 'SeasonCode': 0, 'Mfg_Id': '573-9880954', 'UPC': '822860449228' },
Expand Down

0 comments on commit feab97e

Please sign in to comment.