【问题标题】:Angularjs ui-grid filter cancel eventAngularjs ui-grid过滤器取消事件
【发布时间】:2016-02-02 20:03:51
【问题描述】:

您好,我正在使用角度 ui 网格,我在网格中有过滤器和分组 我默认使用以下

扩展所有行
$scope.expandAll = function(){
    $scope.gridApi.treeBase.expandAllRows();
  };

 $timeout(function() {
    $scope.expandAll();
}, 500);

现在如果用户过滤任何数据中不可用的列

然后删除或取消,不会自动展开

如上所示

当用户清除或取消过滤数据时,我需要所有行自动展开

我发现有一个事件 filterChanged,但我不知道如何使用它

我正在使用以下 plunkr 进行测试

http://plnkr.co/edit/hhIW9R9aX1JlFe4nodJQ?p=preview

谢谢

【问题讨论】:

    标签: angularjs ng-grid angular-ui-grid


    【解决方案1】:

    修改你的 onRegisterApi 方法如下

    onRegisterApi: function( gridApi ) {
      $scope.gridApi = gridApi;
      $scope.gridApi.core.on.filterChanged($scope, function() {        
        var grid = this.grid;
        var isfilterclear = true;
        angular.forEach(grid.columns, function( col ) {
          if(col.filters[0].term){
            isfilterclear = false;
          }
        });
        if(isfilterclear) {
            $timeout(function() {
                $scope.expandAll();
            },500);
        }
      });
    }
    

    见 plunkr http://plnkr.co/edit/1FWDIe?p=preview

    【讨论】:

    • 我最后只是做了 $timeout(function() {$scope.expandAll();},500);在我的 filterChanged 函数中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多