Skip to content

Commit 2a3c4d0

Browse files
author
Jellesma, David
committed
feat(supressSortColumnMenu): Allow optional suppression of sort column menu items
1 parent d74dd46 commit 2a3c4d0

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/js/core/directives/ui-grid-column-menu.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,23 @@ function ( i18nService, uiGridConstants, gridUtil ) {
108108

109109
},
110110

111+
/**
112+
* @ngdoc method
113+
* @methodOf ui.grid.service:uiGridColumnMenuService
114+
* @name suppressSort
115+
* @description determines whether we should suppress the sort asc/desc options
116+
* @param {$scope} $scope the $scope from the uiGridColumnMenu
117+
*
118+
*/
119+
suppressSort: function( $scope ) {
120+
if ($scope.col && $scope.col.colDef && $scope.col.colDef.suppressSort) {
121+
return true;
122+
}
123+
else {
124+
return false;
125+
}
126+
},
127+
111128
/**
112129
* @ngdoc method
113130
* @methodOf ui.grid.service:uiGridColumnMenuService
@@ -169,7 +186,7 @@ function ( i18nService, uiGridConstants, gridUtil ) {
169186
$scope.sortColumn($event, uiGridConstants.ASC);
170187
},
171188
shown: function () {
172-
return service.sortable( $scope );
189+
return service.sortable( $scope ) && !service.suppressSort( $scope );
173190
},
174191
active: function() {
175192
return service.isActiveSort( $scope, uiGridConstants.ASC);
@@ -183,7 +200,7 @@ function ( i18nService, uiGridConstants, gridUtil ) {
183200
$scope.sortColumn($event, uiGridConstants.DESC);
184201
},
185202
shown: function() {
186-
return service.sortable( $scope );
203+
return service.sortable( $scope ) && !service.suppressSort( $scope );
187204
},
188205
active: function() {
189206
return service.isActiveSort( $scope, uiGridConstants.DESC);

test/unit/core/directives/ui-grid-column-menu.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,20 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function () {
145145
});
146146
});
147147

148+
describe('suppressSort: ', function () {
149+
it('everything present: is suppressed', function () {
150+
$scope.col = { uid: 'ui-grid-01x', colDef: { suppressSort: true } };
151+
152+
expect( uiGridColumnMenuService.suppressSort( $scope ) ).toEqual( true );
153+
});
154+
155+
it('colDef missing: is not suppressed', function () {
156+
$scope.col = { uid: 'ui-grid-01x' };
157+
158+
expect( uiGridColumnMenuService.suppressSort( $scope ) ).toEqual( false );
159+
});
160+
});
161+
148162

149163
describe('hideable: ', function () {
150164
it('everything present: is not hideable', function () {

0 commit comments

Comments
 (0)