Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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
You can’t perform that action at this time.