Search code examples
angularjsangular-ui-grid

Getting angular ui grid scroll event


I am trying to register to the scroll event (get notified when new rows appear) like this:

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

But it does not fire.. (angular ui-grid version: v3.0.6)

What would be the correct way to achieve it?


Solution

  • Im not sure about their native events, but you could create your own watcher for their scrolling-event.

    In this Plunkr I made a watcher that broadcasts on scroll.

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

    And your receiver

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

    Plunkr was created from their Grid Scrolling tutorial.