diff --git a/src/js/core/directives/ui-grid-header-cell.js b/src/js/core/directives/ui-grid-header-cell.js index 81f921ddb8..8e4f228249 100644 --- a/src/js/core/directives/ui-grid-header-cell.js +++ b/src/js/core/directives/ui-grid-header-cell.js @@ -86,12 +86,21 @@ $scope.sortable = false; } + // Figure out whether this column is filterable or not if (uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering) { $scope.filterable = true; } else { $scope.filterable = false; } + + // figure out whether we support column menus + if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && + $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false){ + $scope.colMenu = true; + } else { + $scope.colMenu = false; + } function handleClick(evt) { // If the shift key is being held down, add this column to the sort @@ -127,38 +136,39 @@ * */ - // Long-click (for mobile) - var cancelMousedownTimeout; - var mousedownStartTime = 0; - $contentsElm.on('mousedown touchstart', function(event) { - if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { - event = event.originalEvent; - } - - // Don't show the menu if it's not the left button - if (event.button && event.button !== 0) { - return; - } - - mousedownStartTime = (new Date()).getTime(); - - cancelMousedownTimeout = $timeout(function() { }, mousedownTimeout); - - cancelMousedownTimeout.then(function () { - if ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && - $scope.col.colDef && $scope.col.colDef.enableColumnMenu !== false) { - uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); + if ( $scope.sortable || $scope.colMenu ){ + // Long-click (for mobile) + var cancelMousedownTimeout; + var mousedownStartTime = 0; + $contentsElm.on('mousedown touchstart', function(event) { + if (typeof(event.originalEvent) !== 'undefined' && event.originalEvent !== undefined) { + event = event.originalEvent; + } + + // Don't show the menu if it's not the left button + if (event.button && event.button !== 0) { + return; } + + mousedownStartTime = (new Date()).getTime(); + + cancelMousedownTimeout = $timeout(function() { }, mousedownTimeout); + + cancelMousedownTimeout.then(function () { + if ( $scope.colMenu ) { + uiGridCtrl.columnMenuScope.showMenu($scope.col, $elm, event); + } + }); }); - }); - - $contentsElm.on('mouseup touchend', function () { - $timeout.cancel(cancelMousedownTimeout); - }); - - $scope.$on('$destroy', function () { - $contentsElm.off('mousedown touchstart'); - }); + + $contentsElm.on('mouseup touchend', function () { + $timeout.cancel(cancelMousedownTimeout); + }); + + $scope.$on('$destroy', function () { + $contentsElm.off('mousedown touchstart'); + }); + } $scope.toggleMenu = function($event) { diff --git a/test/unit/core/directives/ui-grid-header-cell.spec.js b/test/unit/core/directives/ui-grid-header-cell.spec.js index aab2855e40..8fe39bfe23 100644 --- a/test/unit/core/directives/ui-grid-header-cell.spec.js +++ b/test/unit/core/directives/ui-grid-header-cell.spec.js @@ -110,6 +110,21 @@ describe('uiGridHeaderCell', function () { })); }); + describe('when window is resized', function () { + it('should hide an open menu', function () { + openMenu(); + expect(menu.find('.ui-grid-menu-inner').length).toEqual(1, 'column menu is visible'); + + $(window).trigger('resize'); + $scope.$digest(); + + $timeout.flush(); + $scope.$digest(); + + expect(menu.find('.ui-grid-menu-inner').length).toEqual(0, 'column menu is not visible'); + }); + }); + describe('with enableColumnMenu off', function() { it('should not be present', function () { $scope.gridOpts.enableColumnMenus = false; @@ -133,23 +148,6 @@ describe('uiGridHeaderCell', function () { expect(headers.length).toEqual(2); }); }); - - describe('when window is resized', function () { - it('should hide an open menu', function () { - delete $scope.gridOpts.columnDefs[0].enableColumnMenu; - openMenu(); - expect(menu.find('.ui-grid-menu-inner').length).toEqual(1, 'column menu is visible'); - - $(window).trigger('resize'); - $scope.$digest(); - - $timeout.flush(); - $scope.$digest(); - - expect(menu.find('.ui-grid-menu-inner').length).toEqual(0, 'column menu is not visible'); - }); - }); - // TODO(c0bra): Allow extra items to be added to a column menu through columnDefs });