|
1 | 1 | (function() {
|
2 | 2 | 'use strict';
|
3 | 3 |
|
4 |
| - angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', |
5 |
| - function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) { |
| 4 | + angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', '$rootScope', |
| 5 | + function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService, $rootScope) { |
6 | 6 | // Do stuff after mouse has been down this many ms on the header cell
|
7 | 7 | var mousedownTimeout = 500,
|
8 | 8 | changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa
|
|
226 | 226 | }
|
227 | 227 | };
|
228 | 228 |
|
| 229 | + var setFilter = function (updateFilters) { |
| 230 | + if ( updateFilters ) { |
| 231 | + if ( typeof($scope.col.updateFilters) !== 'undefined' ) { |
| 232 | + $scope.col.updateFilters($scope.col.filterable); |
| 233 | + } |
| 234 | + |
| 235 | + // if column is filterable add a filter watcher |
| 236 | + if ($scope.col.filterable) { |
| 237 | + $scope.col.filters.forEach( function(filter, i) { |
| 238 | + filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { |
| 239 | + if (n !== o) { |
| 240 | + uiGridCtrl.grid.api.core.raise.filterChanged(); |
| 241 | + uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); |
| 242 | + uiGridCtrl.grid.queueGridRefresh(); |
| 243 | + } |
| 244 | + })); |
| 245 | + }); |
| 246 | + $scope.$on('$destroy', function() { |
| 247 | + filterDeregisters.forEach( function(filterDeregister) { |
| 248 | + filterDeregister(); |
| 249 | + }); |
| 250 | + }); |
| 251 | + } else { |
| 252 | + filterDeregisters.forEach( function(filterDeregister) { |
| 253 | + filterDeregister(); |
| 254 | + }); |
| 255 | + } |
| 256 | + } |
| 257 | + }; |
229 | 258 |
|
230 | 259 | var updateHeaderOptions = function() {
|
231 | 260 | var contents = $elm;
|
|
254 | 283 | $scope.sortable = Boolean($scope.col.enableSorting);
|
255 | 284 |
|
256 | 285 | // Figure out whether this column is filterable or not
|
257 |
| - var oldFilterable = $scope.filterable; |
258 |
| - $scope.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); |
259 |
| - |
260 |
| - if ( oldFilterable !== $scope.filterable) { |
261 |
| - if ( typeof($scope.col.updateFilters) !== 'undefined' ) { |
262 |
| - $scope.col.updateFilters($scope.filterable); |
263 |
| - } |
| 286 | + var oldFilterable = $scope.col.filterable; |
| 287 | + $scope.col.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); |
264 | 288 |
|
265 |
| - // if column is filterable add a filter watcher |
266 |
| - if ($scope.filterable) { |
267 |
| - $scope.col.filters.forEach( function(filter, i) { |
268 |
| - filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { |
269 |
| - if (n !== o) { |
270 |
| - uiGridCtrl.grid.api.core.raise.filterChanged(); |
271 |
| - uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); |
272 |
| - uiGridCtrl.grid.queueGridRefresh(); |
273 |
| - } |
274 |
| - })); |
275 |
| - }); |
276 |
| - $scope.$on('$destroy', function() { |
277 |
| - filterDeregisters.forEach( function(filterDeregister) { |
278 |
| - filterDeregister(); |
279 |
| - }); |
280 |
| - }); |
281 |
| - } else { |
282 |
| - filterDeregisters.forEach( function(filterDeregister) { |
283 |
| - filterDeregister(); |
284 |
| - }); |
285 |
| - } |
286 |
| - } |
| 289 | + $scope.$applyAsync(function () { |
| 290 | + setFilter(oldFilterable !== $scope.col.filterable); |
| 291 | + }); |
287 | 292 |
|
288 | 293 | // figure out whether we support column menus
|
289 | 294 | $scope.colMenu = ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false &&
|
|
328 | 333 |
|
329 | 334 | updateHeaderOptions();
|
330 | 335 |
|
| 336 | + if ($scope.col.filterContainer === 'columnMenu' && $scope.col.filterable) { |
| 337 | + $rootScope.$on('menu-shown', function() { |
| 338 | + $scope.$applyAsync(function () { |
| 339 | + setFilter($scope.col.filterable); |
| 340 | + }); |
| 341 | + }); |
| 342 | + } |
| 343 | + |
331 | 344 | // Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs
|
332 | 345 | var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]);
|
333 | 346 |
|
|
0 commit comments