正在获取 angular ui 网格滚动事件

Getting angular ui grid scroll event

我正在尝试像这样注册滚动事件(在出现新行时得到通知):

 $scope.$on('ngGridEventRows', function (event, rows) {
            console.log("Scroll")
  });

但是不火..(angular ui-网格版本:v3.0.6)

实现它的正确方法是什么?

我不确定他们的本地事件,但您可以为他们的滚动事件创建自己的观察者。

在这个Plunkr中,我制作了一个滚动广播的观察者。

$scope.gridOptions.onRegisterApi = function(gridApi){
  $scope.gridApi = gridApi;
  $scope.$watch('gridApi.grid.isScrollingVertically', watchFunc);
  function watchFunc(newData) {
    if(newData === true) {
      $rootScope.$broadcast('scrolled');
    }
  }
};

还有你的接收器

app.controller('SecondCtrl', ['$scope', function ($scope){
  $scope.$on('scrolled', function(event, args) {
    console.log('was scrolled');
  });
}]);

Plunkr 是根据 their Grid Scrolling 教程创建的。

如果您想要更准确的滚动数据(即实际的滚动事件),您可以将网格包裹在一个指令中。我不会在这里包含模板,因为 link 配置是关键部分:

angular.module('my-app').directive('myGrid', function($timeout) {
    return {
      restrict: 'E',
      template: "<div><ui-grid></ui-grid></div>",
      link: function($scope, $element, $attributes) {
        $timeout(function() {
          $('div.ui-grid-viewport').on('scroll', function() {
            // Your event handling here
          });
        });
      }
    };
  });
$scope.$watch("gridApi.grid.isScrollingHorizontally",function(){
//your code
});