angular.module('cssjidi') .service('pagination',[function(){ var _pageCount = 20, _currentPage = 0, _totalRecords = 0, _currentGroup = 1, _groupCount = 5; this.pageSize = function(){ return parseInt(Math.ceil(_totalRecords/_pageCount)); }; this.setPageCount = function(count){ _pageCount = parseInt(count); }; this.setGrountCount = function(count){ _groupCount = parseInt(count); }; this.setRecords = function(count){ _totalRecords = parseInt(count); }; this.groupSize = function(){ return Math.ceil(this.pageSize() / _groupCount); }; this.isFirstPage = function(){ return _currentPage === 1; }; this.isLastPage = function(){ return _currentPage === parseInt(this.getPageSize()); }; this.isFirstGroup = function(){ return _currentGroup === 1; }; this.isLastGroup = function(){ return _currentGroup === this.groupSize(); }; this.setPage = function(number){ _currentPage = parseInt(number); _currentGroup = Math.ceil(_currentPage / _groupCount); }; this.prvePage = function(){ if(this.isFirstPage()) return; _currentPage = 1; this.setPage(1); }; this.nextPage = function(){ if(this.isLastPage) return; _currentPage = this.pageSize(); }; this.pagesList = function(){ var pages = [] , startPage = (_currentGroup-1)*_groupCount, endPage = Math.min(_currentPage,this.pageSize()); for(var number=startPage;number 1){ var leftList = { text: '...', number: _currentGroup*_groupCount+1, limin:_pageCount }; pages.push(leftList); } if(endPage < this.pageSize()){ var rightList = { text: '...', number: _currentGroup*(_groupCount-1), limin:_pageCount }; pages.unshift(rightList); } }; }]) .directive('paging',[function(){ return{ restrict: 'EA', replace: true, template: '', scope: { pager: 'config=?' }, link: function($scope,$element,$attrs){ } }; }]) .controller('demoCtrl',['$scope','pagination',function($scope,pagination){ $scope.pager = {}; pagination.setRecords = 421; }]);