Skip to content

Commit

Permalink
fix: prevent hidden columns triggering unnecessary re-order
Browse files Browse the repository at this point in the history
  • Loading branch information
Dana Greenberg committed Jul 6, 2016
1 parent 592be63 commit 8413d8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/features/move-columns/js/column-movable.js
Expand Up @@ -175,13 +175,14 @@
}

//check columns in between move-range to make sure they are visible columns
var i0 = Math.min(originalPosition, newPosition);
for (i0; i0 < Math.max(originalPosition, newPosition);i0++) {
var pos = (originalPosition < newPosition) ? originalPosition + 1 : originalPosition - 1;
var i0 = Math.min(pos, newPosition);
for (i0; i0 <= Math.max(pos, newPosition); i0++) {
if (columns[i0].visible) {
break;
}
}
if (i0 === Math.max(originalPosition, newPosition)) {
if (i0 > Math.max(pos, newPosition)) {
//no visible column found, column did not visibly move
return;
}
Expand Down
12 changes: 11 additions & 1 deletion src/features/move-columns/test/column-movable.spec.js
Expand Up @@ -183,5 +183,15 @@ describe('ui.grid.moveColumns', function () {
expect(scope.grid.columns[3].name).toBe('company');
expect(scope.grid.columns[4].name).toBe('phone');
});


it('expect column move not to happen if moving across hidden columns', function() {
scope.gridOptions.columnDefs[1].visible = false;
scope.gridApi.colMovable.moveColumn(0, 3);
expect(scope.grid.columns[0].name).toBe('name');
expect(scope.grid.columns[1].name).toBe('gender');
expect(scope.grid.columns[2].name).toBe('age');
expect(scope.grid.columns[3].name).toBe('company');
expect(scope.grid.columns[4].name).toBe('phone');
});

});

0 comments on commit 8413d8e

Please sign in to comment.