Skip to content

Instantly share code, notes, and snippets.

@iammilton82
Last active Oct 15, 2015
Embed
What would you like to do?
AngularJS Pagination
$scope.pagination = {
currentPage: 0,
itemsPerPage: 10,
maxItems: 0,
maxPages: 1,
};
$scope.pagination.nextPage = function(){
if($scope.pagination.currentPage >= 0){
$scope.pagination.currentPage = $scope.pagination.currentPage + 1;
}
};
$scope.pagination.prevPage = function(){
if($scope.pagination.currentPage > 0){
$scope.pagination.currentPage = $scope.pagination.currentPage - 1;
}
};
$scope.pagination.calculateOffset = function(){
var start;
if($scope.pagination.currentPage === 0){
start = 0;
} else {
start = $scope.pagination.currentPage * $scope.pagination.itemsPerPage;
}
return start;
};
<div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<th>Date</th>
<th>Category</th>
</tr>
<tr ng-repeat="item in itemList | orderBy: 'id' : true | limitTo: pagination.itemsPerPage : pagination.calculateOffset()">
<td>Item Date</td>
<td>Business Insurance</td>
</tr>
</table>
</div>
<footer id="pagination">
<button ng-disabled="pagination.currentPage === 0" ng-click="pagination.prevPage()">Previous</button>
<button ng-disabled="pagination.currentPage == (pagination.maxPages - 1)" ng-click="pagination.nextPage()" href>Next Page</button>
</footer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment