Skip to content

Instantly share code, notes, and snippets.

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