如何在清除ui-grid中的所有过滤器时发出/广播事件

时间:2017-09-15 08:42:57

标签: angularjs angular-ui-grid

是否可以在ui-grid中触发clearAllFilters方法时向$ rootScope发出事件(不编辑库)?

为了给出一些上下文,我有一个自定义过滤器,需要在“清除所有过滤器”后调用一个方法。单击菜单项。我打算在组件中加入一个观察者,例如:

$rootScope.$on('clearAllFilters', function(){ });

但是我找不到任何方法从clearFilters方法发出这样的事件。



// snippet from custom filter code

angular
    .module('my-ui-components.grid')
    .controller('MyCustomFilterController', function (_) {

        vm.inputValue = '';
        vm.removeFilter = removeFilter;
        vm.updateFilter = updateFilter;


        //  this method is called successfully on clicking the individual clear button / x
        //  however unable to call it programmatically upon clicking the 'clear all filters' button
        function removeFilter() {
            vm.inputValue = '';
            vm.colFilter.term = '';
        }

        function updateFilter() {
            vm.colFilter.term = parseCapacity(vm.inputValue, fromUnit, vm.toUnit);
        }


        // attempt at watching for filters being cleared however no event emitted to do so
        $rootScope.$on('clearAllFilters', function() {
            vm.removeFilter(); 
        });

<!-- Custom filter template -->

<input type="text" class="ui-grid-filter-input" ng-model="vm.inputValue" ng-change="vm.updateFilter()"
       placeholder="{{vm.colFilter.placeholder}}"/>
<div role="button" class="ui-grid-filter-button" ng-show="vm.inputValue" ng-click="vm.removeFilter()">
    <em class="ui-grid-icon-cancel" ui-grid-one-bind-aria-label="aria.removeFilter" aria-label="Remove Filter">&nbsp;</em>
</div>
&#13;
&#13;
&#13;

0 个答案:

没有答案