Skip to content

Instantly share code, notes, and snippets.

@JohnBaek
Created July 4, 2016 23:45
Show Gist options
  • Save JohnBaek/10cd25a1a366cf117c7155d8e3314c67 to your computer and use it in GitHub Desktop.
Save JohnBaek/10cd25a1a366cf117c7155d8e3314c67 to your computer and use it in GitHub Desktop.
JS_Paging.js
//페이징 구현부
//totalCount 서버로부터부여받은 전체 갯수
//currPosition 현재 페이지 위치
function getPaginate(totalCount,currPosition,showListCount){
var paginate = "";
var maxLinkCount = 10; //링크숫자 보여줄 최대갯수
var lastPosition = 0; //마지막 링크 페이지
var startPosition = 0; //페이징이 시작될 위치
var totalPageCount = 0; //전체페이징 갯수
var block = 0; //범위
var calCurrPosition = (currPosition == 0) ? 1 : currPosition + 1;
//전체 페이지수를 계산
totalPageCount = Math.floor(totalCount / showListCount);
//페이징이 시작될 위치를 계산
var block = Math.ceil((calCurrPosition / maxLinkCount));
startPosition = ( (block-1) * maxLinkCount ) + 1;
//페이징 마지막 리스트를 계산
lastPosition = (startPosition + maxLinkCount) -1;
if(lastPosition > totalPageCount){
lastPosition = totalPageCount + 1;
}
var linkNumber = 0;
//처음버튼 삽입
if(currPosition != 0){
paginate += "<a href=\"#\" onclick=\"drawList(0)\">처음</a> ";
}
var preKey = 0;
//처음버튼 삽입
if(currPosition != 0){
preKey = currPosition - 1;
paginate += "<a href=\"#\" onclick=\"drawList("+preKey+")\">이전</a> ";
}
for(startPosition; startPosition <= lastPosition; startPosition++){
linkNumber = startPosition - 1;
if(lastPosition == 1){
paginate += " | <a href=\"#\" onclick=\"drawList(" + linkNumber +")\"><b>" + startPosition + "</b></a> | ";
}else if(currPosition == linkNumber){
paginate += " | <a href=\"#\" onclick=\"drawList(" + linkNumber +")\"><b>" + startPosition + "</b></a> ";
}else{
paginate += " | <a href=\"#\" onclick=\"drawList(" + linkNumber +")\">" + startPosition + "</a> ";
}
}
if(lastPosition != 1){
paginate += " | ";
}
var nextKey =0;
//'다음' 이동 삽입
if(currPosition+1 != totalPageCount+1){
nextKey = currPosition + 1;
paginate += "<a href=\"#\" onclick=\"drawList("+nextKey+")\">다음</a> ";
}
//'끝' 이동 삽입
if(currPosition != totalPageCount){
paginate += "<a href=\"#\" onclick=\"drawList("+totalPageCount+")\">끝</a> ";
}
if(totalCount == 0)
paginate = "";
return paginate;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment