Last active
October 15, 2015 15:59
-
-
Save iammilton82/eae905cf2aecd648d229 to your computer and use it in GitHub Desktop.
AngularJS Pagination
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.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; | |
}; |
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
<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