Skip to content

Instantly share code, notes, and snippets.

@qazimobeen
Created May 14, 2018 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qazimobeen/45ec08011bb937eb66b0eb4a83d0a5a1 to your computer and use it in GitHub Desktop.
Save qazimobeen/45ec08011bb937eb66b0eb4a83d0a5a1 to your computer and use it in GitHub Desktop.
$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