-
Notifications
You must be signed in to change notification settings - Fork 2.5k
feat(filter): add filterContainer option to allow a column filter to be placed in column menu #6901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,8 @@ | ||||||
(function() { | ||||||
'use strict'; | ||||||
|
||||||
angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', | ||||||
function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService) { | ||||||
angular.module('ui.grid').directive('uiGridHeaderCell', ['$compile', '$timeout', '$window', '$document', 'gridUtil', 'uiGridConstants', 'ScrollEvent', 'i18nService', '$rootScope', | ||||||
function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, ScrollEvent, i18nService, $rootScope) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move rootScope to the start? It is more of a personal preference, but I like having all of the $ variables grouped together.
Suggested change
|
||||||
// Do stuff after mouse has been down this many ms on the header cell | ||||||
var mousedownTimeout = 500, | ||||||
changeModeTimeout = 500; // length of time between a touch event and a mouse event being recognised again, and vice versa | ||||||
|
@@ -226,6 +226,35 @@ | |||||
} | ||||||
}; | ||||||
|
||||||
var setFilter = function (updateFilters) { | ||||||
if ( updateFilters ) { | ||||||
if ( typeof($scope.col.updateFilters) !== 'undefined' ) { | ||||||
$scope.col.updateFilters($scope.col.filterable); | ||||||
} | ||||||
|
||||||
// if column is filterable add a filter watcher | ||||||
if ($scope.col.filterable) { | ||||||
$scope.col.filters.forEach( function(filter, i) { | ||||||
filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { | ||||||
if (n !== o) { | ||||||
uiGridCtrl.grid.api.core.raise.filterChanged(); | ||||||
uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); | ||||||
uiGridCtrl.grid.queueGridRefresh(); | ||||||
} | ||||||
})); | ||||||
}); | ||||||
$scope.$on('$destroy', function() { | ||||||
filterDeregisters.forEach( function(filterDeregister) { | ||||||
filterDeregister(); | ||||||
}); | ||||||
}); | ||||||
} else { | ||||||
filterDeregisters.forEach( function(filterDeregister) { | ||||||
filterDeregister(); | ||||||
}); | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
var updateHeaderOptions = function() { | ||||||
var contents = $elm; | ||||||
|
@@ -254,36 +283,12 @@ | |||||
$scope.sortable = Boolean($scope.col.enableSorting); | ||||||
|
||||||
// Figure out whether this column is filterable or not | ||||||
var oldFilterable = $scope.filterable; | ||||||
$scope.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); | ||||||
|
||||||
if ( oldFilterable !== $scope.filterable) { | ||||||
if ( typeof($scope.col.updateFilters) !== 'undefined' ) { | ||||||
$scope.col.updateFilters($scope.filterable); | ||||||
} | ||||||
var oldFilterable = $scope.col.filterable; | ||||||
$scope.col.filterable = Boolean(uiGridCtrl.grid.options.enableFiltering && $scope.col.enableFiltering); | ||||||
|
||||||
// if column is filterable add a filter watcher | ||||||
if ($scope.filterable) { | ||||||
$scope.col.filters.forEach( function(filter, i) { | ||||||
filterDeregisters.push($scope.$watch('col.filters[' + i + '].term', function(n, o) { | ||||||
if (n !== o) { | ||||||
uiGridCtrl.grid.api.core.raise.filterChanged(); | ||||||
uiGridCtrl.grid.api.core.notifyDataChange( uiGridConstants.dataChange.COLUMN ); | ||||||
uiGridCtrl.grid.queueGridRefresh(); | ||||||
} | ||||||
})); | ||||||
}); | ||||||
$scope.$on('$destroy', function() { | ||||||
filterDeregisters.forEach( function(filterDeregister) { | ||||||
filterDeregister(); | ||||||
}); | ||||||
}); | ||||||
} else { | ||||||
filterDeregisters.forEach( function(filterDeregister) { | ||||||
filterDeregister(); | ||||||
}); | ||||||
} | ||||||
} | ||||||
$scope.$applyAsync(function () { | ||||||
setFilter(oldFilterable !== $scope.col.filterable); | ||||||
}); | ||||||
|
||||||
// figure out whether we support column menus | ||||||
$scope.colMenu = ($scope.col.grid.options && $scope.col.grid.options.enableColumnMenus !== false && | ||||||
|
@@ -328,6 +333,14 @@ | |||||
|
||||||
updateHeaderOptions(); | ||||||
|
||||||
if ($scope.col.filterContainer === 'columnMenu' && $scope.col.filterable) { | ||||||
$rootScope.$on('menu-shown', function() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is $rootScope needed here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, it might make sense to have tests that specifically change that setFilter works as expected when menu-shown event is triggered, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||
$scope.$applyAsync(function () { | ||||||
setFilter($scope.col.filterable); | ||||||
}); | ||||||
}); | ||||||
} | ||||||
|
||||||
// Register a data change watch that would get triggered whenever someone edits a cell or modifies column defs | ||||||
var dataChangeDereg = $scope.grid.registerDataChangeCallback( updateHeaderOptions, [uiGridConstants.dataChange.COLUMN]); | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.