2

My infinite scroll is not working 2nd time onward. I mean it loads the data first time while scrolling, after loading it also append the data to my data set but again if I scroll then it does not calling my load method.

Attached Plunker here. Removed $http code with $timeout to reproduce problem on plunker. $timeout also same problem persist.

var app = angular.module('plunker', ['ui.grid', 'ui.grid.infiniteScroll']);

    angular.module('plunker').controller('ListController',ListController);
    ListController.$inject = ['$scope', '$timeout', '$q'];                              
    function ListController  ( $scope,   $timeout,   $q) {
    	$scope.itemsPerPage = 20;
    	$scope.lastPage = 0;
    	$scope.data = [];
    	
    	var request = {"startAt" : "1","noOfRecords" : $scope.itemsPerPage};
    	
    	$scope.gridOptions = {
		    infiniteScrollDown: true,
		    columnDefs: [
		      { field: 'id', name:'ID'},
		      { field: 'name', name:'My Name'}
		    ],
		    data: 'data',
		    onRegisterApi: function(gridApi){
		      gridApi.infiniteScroll.on.needLoadMoreData($scope, $scope.loadMoreData);
		      $scope.gridApi = gridApi;
		    }
		 };
    	
		 
	   $scope.loadMoreData = function() {
	     var promise = $q.defer();
	     $timeout(function () {
           //Sample Data Creation Start
	       var arrayObj = [];
	       for(var i=0; i<$scope.itemsPerPage; i++){
	         arrayObj.push({id:Math.random()*100, name:'Name '+Math.random()});
	       }
           //Sample Data Creation End
	       $scope.data = $scope.data.concat(arrayObj);
			   console.log($scope.data);
			   promise.resolve();
	     }, Math.random()*1000);
	     return promise.promise;
	  };
		
	  	$scope.loadMoreData();
    }
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.css" type="text/css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.3.20/angular.js" data-semver="1.3.20"></script>
    <script src="https://cdn.rawgit.com/angular-ui/bower-ui-grid/master/ui-grid.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="ListController">
    <div data-ui-grid="gridOptions" class="grid" data-ui-grid-infinite-scroll></div>
  </body>

</html>

Seems I am missing some event attachment after 1st scroll down load. Please help.

1 Answer 1

2

You are indeed missing the notification, that your new data was loaded.

$scope.gridApi.infiniteScroll.dataLoaded()

Here is an updated version of your Plunkr. See line 36 in app.js.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, your suggestion is working good. But I am facing a new problem while all of my content finished loading scroll bar is not staying on last result. It jumps to last few result. Here is another question I posted related to that. stackoverflow.com/questions/33665641/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.