Created
July 21, 2014 18:41
-
-
Save harveyxia/a4424cdd86a98cf42886 to your computer and use it in GitHub Desktop.
Pagination in ejs
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
<!-- provide these args: currentPage, totalPages, and queryParams --> | |
<!-- variables i and j control the number of pages to show on the left and right --> | |
<div class='pagination-container col-xs-12'> | |
<ul class='pagination pagination-lg'> | |
<% if (currentPage != 1) { %> | |
<li><a class='ajax' href="/<%= paginateItem %>/?page=<%= currentPage - 1 %><%= queryParams%>">«</a></li> | |
<% } else { %> | |
<li class='disabled'><a class='ajax' href="javascript:void(0)">«</a></li> | |
<% } %> | |
<% var i = 5, j = 5; %> | |
<% i += Math.max(0, currentPage + j - totalPages) %> | |
<% j -= Math.max(0, currentPage + j - totalPages) %> | |
<% for (var i; i > 0; i--) { %> | |
<% if (currentPage - i > 0) { %> | |
<li><a class='ajax' href="/<%= paginateItem %>?page=<%=currentPage - i%><%= queryParams%>"><%= currentPage - i %></a></li> | |
<% } else { %> | |
<% j++ %> | |
<% } %> | |
<% } %> | |
<li class='active ajax'><a href="javascript:void()"><%= currentPage %></a></li> | |
<% for (var a = 1; a <= j && currentPage + a <= totalPages; a++) { %> | |
<li><a class='ajax' href="/<%= paginateItem %>?page=<%=currentPage + a%><%= queryParams%>"><%= currentPage + a %></a></li> | |
<% } %> | |
<% if (currentPage != totalPages) { %> | |
<li><a class='ajax' href="/<%= paginateItem %>/?page=<%= currentPage + 1 %><%= queryParams%>">»</a></li> | |
<% } else { %> | |
<li class='disabled'><a class='ajax' href="javascript:void(0)">»</a></li> | |
<% } %> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's this? Is it: << 1 2 3 4 5 ...10 11 12 13 14 15>> ?