3

I am fetching data from server its loading time is quite good, But while rendering all data almost 3k rows to view (angularJs) browser get freeze and after some time its crashed also.
I tried pagination but after crossing 500 rows its start freezing. Some time its load all data into view but while scrolling or applying some event like click again got freeze.

Here is the code where i am listing all data.

 <div class="divRow" ng-repeat="list in campaignDetailListfilterCopy.campaign_items | limitTo:totalDisplayed"">
                <div class="divCell">
      <div style="float:left;width: 325px;">
         <div>
           <span ng-if="list.monitor_type == 3">{{list.items.media_id}}</span>
             <div class="moImgPreview hoverPreview creativePreview">   <img alt=""ng-src="{{list.items.media_thumbnail}}"/></div>
           </span>
       </div>
       <p><strong class="lang" key="campaign_List_view_text2">Location</strong><span>{{list.items.media_address}}</span> </p>                                                                                                                                
    </div>
</div>

<button class="btn" ng-click="loadMore()">Load more</button>

//the controller
$scope.totalDisplayed = 20;

$scope.loadMore = function () {
  $scope.totalDisplayed += 20;  
};

$scope.campaignDetailListfilterCopy.campaign_items = data;
10
  • 500 rows fit on no screen that will ever load your site. Try loading as many items as 2 screens full and only load more when the user needs it. I don't know how big your rows are, but I'd say 50-75 rows should be the max you should render at once Commented Jul 31, 2019 at 8:44
  • 500 rows means, after clicking on load more from 20 rows to increase 500 rows then its creating problem Commented Jul 31, 2019 at 8:47
  • add 50 more at that point, not 500 Commented Jul 31, 2019 at 8:56
  • Also, are you adding them one by one or all at the same time? Commented Jul 31, 2019 at 8:56
  • I have to display 2k rows. initially i m displaying 20 rows and there is a button to load more , after clicking load more its loading 20 more rows from data (already loaded data from server). Now after clicking again and again on load more when its reached 500 or more row, then browser getting freezing on next load more click Commented Jul 31, 2019 at 9:02

1 Answer 1

3

you should keep two separate lists one holds all the data and the other one should hold only 20 at first and when you press load more it should add 20 more to the list from the list that has all the data with a loop

$scope.loadMore = function(){
let start = $scope.listToShow.length;
 for(let i = start; i<= start + 20; i++){
   if(angular.isDefined($scope.campaignDetailListfilterCopy.campaign_items[i]) {    
 $scope.listToShow.push($scope.campaignDetailListfilterCopy.campaign_items[i]);
   }

 }
}

$scope.listToShow= []
$scope.campaignDetailListfilterCopy.campaign_items = data;
$scope.loadMore();




And in your html

<div class="divRow" ng-repeat="list in listToShow">

and maybe inside your list you can add a button that calls the loadMore

<button ng-click="loadMore()"> load more</button>
Sign up to request clarification or add additional context in comments.

5 Comments

showing error :- listToShow is not defined . is $scope.listToShow and listToShow are two diffrent varriable or same? if both are same then it will go in infinite loop..please clear little more @Jazib
Hi nitish yes they are the same variables. you should define it on top of your controller as empty list, and when you get the data you call $scope.loadMore() Ah nice catch. I will update my answer to avoid the infinite loop
@NitishKumar check it out now, I also added a condition so you don't get the undefined error if index is something that exceeds the length of the list containing all data
now your code is working fine but .it did not solve my problem.. still same issue. after reaching more number or rows its start freezing.
@NitishKumar can you create a plunkr ?

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.