Created
February 8, 2015 04:10
-
-
Save cssjidi/7ce5511564d26b251d62 to your computer and use it in GitHub Desktop.
angularjs-pagination [angularjs-pagination] // source http://jsbin.com/xetiwa/12
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="[angularjs-pagination]"> | |
<meta charset="utf-8"> | |
<title>angularjs-pagination</title> | |
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css"> | |
</head> | |
<body> | |
<paging config="pager"></paging> | |
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js"></script> | |
<script src="http://cdn.bootcss.com/angular.js/1.3.7/angular-sanitize.js"></script> | |
<script id="jsbin-javascript"> | |
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<endPage;number++){ | |
var listArray = { | |
text:number, | |
page:number, | |
limit:_pageCount | |
}; | |
pages.push(listArray); | |
} | |
if(startPage > 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: '<div class="pagination"></div>', | |
scope: { | |
pager: 'config=?' | |
}, | |
link: function($scope,$element,$attrs){ | |
} | |
}; | |
}]) | |
.controller('demoCtrl',['$scope','pagination',function($scope,pagination){ | |
$scope.pager = {}; | |
pagination.setRecords = 421; | |
}]); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">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<endPage;number++){ | |
var listArray = { | |
text:number, | |
page:number, | |
limit:_pageCount | |
}; | |
pages.push(listArray); | |
} | |
if(startPage > 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: '<div class="pagination"></div>', | |
scope: { | |
pager: 'config=?' | |
}, | |
link: function($scope,$element,$attrs){ | |
} | |
}; | |
}]) | |
.controller('demoCtrl',['$scope','pagination',function($scope,pagination){ | |
$scope.pager = {}; | |
pagination.setRecords = 421; | |
}]);</script></body> | |
</html> |
This file contains hidden or 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
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<endPage;number++){ | |
var listArray = { | |
text:number, | |
page:number, | |
limit:_pageCount | |
}; | |
pages.push(listArray); | |
} | |
if(startPage > 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: '<div class="pagination"></div>', | |
scope: { | |
pager: 'config=?' | |
}, | |
link: function($scope,$element,$attrs){ | |
} | |
}; | |
}]) | |
.controller('demoCtrl',['$scope','pagination',function($scope,pagination){ | |
$scope.pager = {}; | |
pagination.setRecords = 421; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment