Skip to content

Commit

Permalink
option to disable GridMenu close on scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonakshi Gupta authored and mportuga committed Jan 12, 2023
1 parent 5315d40 commit 6d3f006
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/core/src/js/directives/ui-grid-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,20 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
// *** Auto hide when click elsewhere ******
var applyHideMenu = function(event) {
if ($scope.shown) {
if ($scope.col && $scope.col.filterContainer === 'columnMenu') {
var elm = document.querySelector('.ui-grid-column-menu').querySelector('[ui-grid-filter]');
if (elm && elm.contains(event.target)) {
return false;
var disableGridMenuHideOnScroll = uiGridCtrl && uiGridCtrl.grid && uiGridCtrl.grid.options ? uiGridCtrl.grid.options.disableGridMenuHideOnScroll : null;

if (event.type !== 'scroll' || !disableGridMenuHideOnScroll) {
if ($scope.col && $scope.col.filterContainer === 'columnMenu') {
var elm = document.querySelector('.ui-grid-column-menu').querySelector('[ui-grid-filter]');
if (elm && elm.contains(event.target)) {
return false;
}
}
}

$scope.$apply(function () {
$scope.hideMenu();
});
$scope.$apply(function () {
$scope.hideMenu();
});
}
}
};

Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/js/factories/GridOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ angular.module('ui.grid')
*/
baseOptions.gridMenuTemplate = baseOptions.gridMenuTemplate || 'ui-grid/uiGridMenu';

/**
* @ngdoc string
* @name disableGridMenuHideOnScroll
* @propertyOf ui.grid.class:GridOptions
* @description 'false' by default. When provided, this setting disables Grid Menu Hide On Scroll
*/
baseOptions.disableGridMenuHideOnScroll = baseOptions.disableGridMenuHideOnScroll || false;

/**
* @ngdoc string
* @name menuButtonTemplate
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/js/factories/ScrollEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
self.verticalScrollLength = -9999999;
self.horizontalScrollLength = -999999;

self.type = 'scroll';

/**
* @ngdoc function
Expand Down
5 changes: 5 additions & 0 deletions packages/core/test/core/factories/GridOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('GridOptions factory', function () {
gridMenuTemplate: 'ui-grid/uiGridMenu',
menuButtonTemplate: 'ui-grid/ui-grid-menu-button',
menuItemTemplate: 'ui-grid/uiGridMenuItem',
disableGridMenuHideOnScroll: false,
appScopeProvider: null
});
});
Expand Down Expand Up @@ -107,6 +108,7 @@ describe('GridOptions factory', function () {
menuButtonTemplate: 'testMenuButton',
menuItemTemplate: 'testMenuItem',
extraOption: 'testExtraOption',
disableGridMenuHideOnScroll: true,
appScopeProvider : 'anotherRef'
};
expect( GridOptions.initialize(options) ).toEqual({
Expand Down Expand Up @@ -155,6 +157,7 @@ describe('GridOptions factory', function () {
menuButtonTemplate: 'testMenuButton',
menuItemTemplate: 'testMenuItem',
extraOption: 'testExtraOption',
disableGridMenuHideOnScroll: true,
appScopeProvider : 'anotherRef'
});
});
Expand Down Expand Up @@ -205,6 +208,7 @@ describe('GridOptions factory', function () {
gridMenuTemplate: 'testGridMenu',
menuButtonTemplate: 'testMenuButton',
menuItemTemplate: 'testMenuItem',
disableGridMenuHideOnScroll: false,
extraOption: 'testExtraOption'
};
expect( GridOptions.initialize(options) ).toEqual({
Expand Down Expand Up @@ -253,6 +257,7 @@ describe('GridOptions factory', function () {
menuButtonTemplate: 'testMenuButton',
menuItemTemplate: 'testMenuItem',
extraOption: 'testExtraOption',
disableGridMenuHideOnScroll: false,
appScopeProvider : null
});
});
Expand Down

0 comments on commit 6d3f006

Please sign in to comment.