angular-ui / bootstrap

PLEASE READ THE PROJECT STATUS BELOW. Native AngularJS (Angular) directives for Bootstrap. Smaller footprint (20kB gzipped), no 3rd party JS dependencies (jQuery, bootstrap JS) required. Please read the README.md file before submitting an issue!
http://angular-ui.github.io/bootstrap/
MIT License
14.3k stars 6.74k forks source link

Angular JS Pagination Refresh issue #6689

Closed dheerajkumar92 closed 6 years ago

dheerajkumar92 commented 6 years ago

I have implemented pagination in Angular. But got stuck on one issue. Every time when I click on Next, it display the next results but after a while, page automatically refreshes and resets the page to 1. Here is my code.

 <table class="table table-condensed table-hover">             
            <tr>  
                <th ng-click="sort('webTitle')">Project Name</th>   
                <th ng-click="sort('siteDocs')">Document Name</th>                 
                <th ng-click="sort('moderationStatus')">Approval Status</th>  
                <th ng-click="sort('workflowPPI')">Internal Status</th>     
<th ng-click="sort('statuswf')">Status</th> 
<th ng-click="sort('percentcomplete')">% Complete</th> 
<th ng-click="sort('assignedto')">Assigned To</th> 
<th ng-click="sort('duedate')">Due Date</th>                
            </tr>  

         <tr ng-repeat="item in data.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage))|orderBy:sortKey:reverse|filter:search|| startFrom:currentPage*pageSize | limitTo:pageSize">        
                <td>{{item.webTitle}}</td>  
                <td ng-switch="item.url == ''">
    <span ng-switch-when="false"><a href="{{item.url}}">{{item.siteDocs}}</a></span>
    <span ng-switch-when="true">{{item.siteDocs}}</span>
  </td>               
                <td>{{item.moderationStatus}}</td>
                <td>{{item.workflowPPI}}</td>
                <td>{{item.statuswf}}</td>              
                <td>{{item.percentcomplete}}</td>
                <td>{{item.assignedto}}</td>
                <td>{{item.duedate}}</td>
                </div>
                </tr>  

        </table>  
        View <select ng-model="viewby" ng-change="setItemsPerPage(viewby)"><option>3</option><option>5</option><option>10</option><option>20</option><option>30</option><option>40</option><option>50</option></select> records at a time.
         <pagination total-items="totalItems" ng-model="currentPage" ng-change="pageChanged()" class="pagination-sm" items-per-page="itemsPerPage"></pagination>
    <pre>The selected page no: {{currentPage}}</pre>
    <button class="btn btn-info" ng-click="setPage(3)">Set current page to: 3</button>
      <button ng-disabled="currentPage == 0" ng-click="currentPage=currentPage-1">
        Previous
    </button>
    {{currentPage+1}}/{{numberOfPages()}}
    <button ng-disabled="currentPage >= totalItems/viewby - 1" ng-click="currentPage=currentPage+1">
        Next
    </button>

    </div>  
</div>  

<script type="text/javascript">
var count=parseInt(0);
var arr=[];
wf=[];
var siteInformation;
sites=[];   
var app = angular.module('SharePointAngApp', ['ui.bootstrap']); 

var obj=[];

app.controller('spCustomerController', function($scope) 
        {   
        $scope.sort = function(keyname){
        $scope.sortKey = keyname;   //set the sortKey to the param passed
        $scope.reverse = !$scope.reverse; //if true make it false and vice versa
                            }
        GetListItems($scope); 
        $scope.data=sites;

  $scope.viewby = 10;
 $scope.totalItems = $scope.data.length;
  $scope.currentPage = 1;
  $scope.itemsPerPage = $scope.viewby;
  $scope.maxSize = 5; //Number of pager buttons to show

  $scope.numberOfPages=function(){
        return Math.ceil($scope.data.length/$scope.viewby);
  }

  $scope.setPage = function (pageNo) {
    $scope.currentPage = pageNo;
  };

  $scope.pageChanged = function() {
    console.log('Page changed to: ' + $scope.currentPage);
  };

$scope.setItemsPerPage = function(num) {
  $scope.itemsPerPage = num;
  $scope.currentPage = 1; //reset to first page
}
        });
icfantv commented 6 years ago

Closing this as this project is no longer being maintained, per the README and the ISSUE_TEMPLATE.