muriithi
muriithi

Reputation: 131

Angular UI-Bootstrap Pagination

I have my ng-repeat template as;

ng-repeat="student in students| filter:searchText | filter: paginate "

while in the controller I have;

$scope.currentPage = 1; 
$scope.itemsPerPage = 20;  
$scope.paginate = function (value) {  
    var begin, end, index;  
    begin = ($scope.currentPage - 1) * $scope.itemsPerPage;  
    end = begin + $scope.itemsPerPage;  
    index = $scope.students.indexOf(value);  
    return (begin <= index && index < end);  
}; 

The pagination is working but when I filter by seachText the filtered results stay in their old paginated pages.

How can I make the filtered results come to the first page.

Upvotes: 2

Views: 315

Answers (1)

Krishna Patel
Krishna Patel

Reputation: 275

try this...

var sap=angular.module('doApp',['ui.bootstrap']);
sap.filter('startFrom',function(){ 
    return function(input,start){
        if(input){
            start =+start;
            return input.slice(start);
        }
        return [];
        }
});

and make this change to ng-repeat..

<tr ng-repeat="student in filtered=(students | filter:serachText) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">

Where entrylimit could be

 $scope.entryLimit=5;

just add this entrylimit in your paginate function. hope this will help..

Upvotes: 0

Related Questions