简体   繁体   English

如何在AngularJS ui-grid中更改网格时收到通知?

[英]How to get notified when grid changed in AngularJS ui-grid?

If there is a way in ui-grid that I can know a grid is finish updating the rows?(like a filter is being applied etc)? 如果在ui-grid中有一种方法我可以知道网格是否已完成更新行?(就像正在应用过滤器等)? I want to run some function after the grid view changes. 我想在网格视图更改后运行一些函数。

I tried the following method: 我尝试了以下方法:

$scope.filteredRows = $scope.gridApi.core.getVisibleRows($scope.gridApi.grid);

$scope.$watch('filteredRows', function(){console.log('view updated');});

The above approach works when the grid just finish initiating, after that, it won't work anymore. 当网格刚刚完成启动时,上述方法有效,之后,它将不再起作用。

I also tried using the filterChanged api: 我也尝试过使用filterChanged api:

$scope.gridApi.core.on.filterChanged($scope, function() {
    console.log('filter changed');
    foo();
});

The problem with this method is that although I can get notified when the filter is changed, but if the grid is very large, it needs some time to finish updating the view, and before that, the function foo() is being called before the grid update is finished. 这种方法的问题在于虽然我可以在更改过滤器时收到通知,但是如果网格非常大,则需要一些时间来完成视图更新,在此之前,函数foo()在调用之前被调用。网格更新完成。

Any idea will be appreciated. 任何想法将不胜感激。

I've seen use of $scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); 我见过使用$scope.grid.api.core.on.rowsRendered( $scope, $scope.col.updateAggregationValue ); in ui-grid-footer-cell.js. 在ui-grid-footer-cell.js中。 I'm not sure exactly when rowsRendered fires, but given it's being used to calculate aggregations and aggregations require knowledge whenever the rows are changed, and must run after the rowsProcessors finish running, there's a good chance that it's what you want. 我不确定rowsRendered何时触发,但鉴于它被用于计算聚合和聚合,每当行更改时都需要知识,并且必须在rowsProcessors完成运行后运行,很有可能它就是你想要的。

EDIT: the framework to use it would be: 编辑:使用它的框架将是:

  1. Define a function that you want to call when the visible rows have changed 定义在可见行更改时要调用的函数

    var myFunction = function() { do some stuff };

  2. Set this function to be called whenever rows are rendered 设置此函数以在呈现行时调用

    $scope.gridApi.core.on.rowsRendered( $scope, myFunction );

Well, I found a workaround, in order to call the function after the grid is updated, which takes some time, I added a delay in filterChanged event: 好吧,我找到了一个解决方法,为了在网格更新后调用该函数,这需要一些时间,我在filterChanged事件中添加了一个延迟:

$scope.gridApi.core.on.filterChanged($scope, function() {
    console.log('filter changed');
    $timeout(foo(),800);
});

To use the $timeout , you need to add that to your controller first. 要使用$timeout ,您需要先将其添加到控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM