Created
May 14, 2018 10:40
-
-
Save qazimobeen/45ec08011bb937eb66b0eb4a83d0a5a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.pageNoChanged = function (value) { | |
// evaluates what is your current situation and can page no be changed? | |
if ($scope.currentPage === 1 && value < -1) { | |
//console.log("you can't request page change"); | |
// if you are on FIRST page and requested FIRST page | |
return; | |
} | |
else if ($scope.currentPage === $scope.lastPage && value > 1) { | |
//console.log("you can't request page change"); | |
// if you are on LAST page and requested LAST page | |
return; | |
} | |
else if ($scope.currentPage === 1 && value === -1) { | |
//console.log("you can't request page change"); | |
// if you are on FIRST page and requested previous page | |
return; | |
} | |
else if ($scope.currentPage === $scope.lastPage && value === 1) { | |
//console.log("you can't request page change"); | |
// if you are on LAST page and requested next page | |
return; | |
} | |
// evaluates what change in page no is requested? | |
if (value > 1) { | |
// if last page is requested | |
$scope.currentPage = $scope.lastPage; | |
} | |
else if (value < -1) { | |
// if first page is requested | |
$scope.currentPage = parseInt(1); | |
} | |
else { | |
// next or previous page are requested | |
$scope.currentPage = parseInt($scope.currentPage) + parseInt(value); | |
} | |
var begin = (($scope.currentPage - 1) * $scope.pageSize.value); | |
var end = begin + parseInt($scope.pageSize.value); | |
if (parseInt(end) > $scope.originalItems.length) { | |
// set the last item index to length of array | |
end = $scope.originalItems.length; | |
} | |
$scope.items = $scope.originalItems.slice(begin, end); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment