admin管理员组文章数量:1023691
I have a node project with some simple admin interfaces. One page shows a list of users, it's paginated with a bootstrap paginator and when there's several thousand users the pagination looks like
Here's the code:
<nav>
<div class="text-center">
<ul class="pagination pagination-sm">
<li
<% if(page <= 0) { %>
class="disabled"
<% } %>
><a href="?page=<%= page <= 0 ? 0 : page - 1 %>">«</a></li>
<% for(var i = 0; i < pages; i++) { %>
<li
<% if(page == i) { %>
class="active"
<% } %>
><a href="?page=<%= i %>"><%= i + 1 %></a></li>
<% } %>
<li <% if(page > pages - 1) { %>class="disabled"
<% } %>
><a href="?page=<%= page > pages - 1 ? parseInt(pages) : 1 + parseInt(page) %>">»</a></li>
</ul>
</div>
I'm not an html person. Here are my questions:
1: How does the href ?page=n
work? What's the ?
do? I assume there's logic somewhere that directs the browser to show the new page but I'm not sure where.
2: Is there a good way to add an ellipsis or some other truncated pagination? I suppose I can show ten pages and bookend it with the single page advancers and bookend that with something to show the next/previous ten pages. I'm not entirely sure how to make that happen. Understanding how the href works would help.
Thanks!
I have a node project with some simple admin interfaces. One page shows a list of users, it's paginated with a bootstrap paginator and when there's several thousand users the pagination looks like
Here's the code:
<nav>
<div class="text-center">
<ul class="pagination pagination-sm">
<li
<% if(page <= 0) { %>
class="disabled"
<% } %>
><a href="?page=<%= page <= 0 ? 0 : page - 1 %>">«</a></li>
<% for(var i = 0; i < pages; i++) { %>
<li
<% if(page == i) { %>
class="active"
<% } %>
><a href="?page=<%= i %>"><%= i + 1 %></a></li>
<% } %>
<li <% if(page > pages - 1) { %>class="disabled"
<% } %>
><a href="?page=<%= page > pages - 1 ? parseInt(pages) : 1 + parseInt(page) %>">»</a></li>
</ul>
</div>
I'm not an html person. Here are my questions:
1: How does the href ?page=n
work? What's the ?
do? I assume there's logic somewhere that directs the browser to show the new page but I'm not sure where.
2: Is there a good way to add an ellipsis or some other truncated pagination? I suppose I can show ten pages and bookend it with the single page advancers and bookend that with something to show the next/previous ten pages. I'm not entirely sure how to make that happen. Understanding how the href works would help.
Thanks!
Share Improve this question asked Aug 23, 2016 at 14:00 MayNotBeMayNotBe 2,1403 gold badges33 silver badges50 bronze badges1 Answer
Reset to default 3Paginate library takes most of the heavy burden of actually implementing pagination off you. You simply need to calculate three variables: Number of totals items, items per page, and current page number.
var totalItems, itemsPerPage, pageNum;
// calculate the data for above variables and pass them in below method
var pagination = paginate.page(totalItems, itemsPerPage, pageNum);
var paginationHtml = pagination.render({ baseUrl: '/' }); //the link to pass to href, page number will be added as query paramtere to it e.g. /?page=6
paginationHtml
now contains the bootstrap's pagination HTML. Simply pass it as parameter to ejs template and render it:
<%- paginationHtml %>
This one liner will give you the following:
You can change the styling by modifying bootstrap classes for pagination (as done in the example screenshots).
I have a node project with some simple admin interfaces. One page shows a list of users, it's paginated with a bootstrap paginator and when there's several thousand users the pagination looks like
Here's the code:
<nav>
<div class="text-center">
<ul class="pagination pagination-sm">
<li
<% if(page <= 0) { %>
class="disabled"
<% } %>
><a href="?page=<%= page <= 0 ? 0 : page - 1 %>">«</a></li>
<% for(var i = 0; i < pages; i++) { %>
<li
<% if(page == i) { %>
class="active"
<% } %>
><a href="?page=<%= i %>"><%= i + 1 %></a></li>
<% } %>
<li <% if(page > pages - 1) { %>class="disabled"
<% } %>
><a href="?page=<%= page > pages - 1 ? parseInt(pages) : 1 + parseInt(page) %>">»</a></li>
</ul>
</div>
I'm not an html person. Here are my questions:
1: How does the href ?page=n
work? What's the ?
do? I assume there's logic somewhere that directs the browser to show the new page but I'm not sure where.
2: Is there a good way to add an ellipsis or some other truncated pagination? I suppose I can show ten pages and bookend it with the single page advancers and bookend that with something to show the next/previous ten pages. I'm not entirely sure how to make that happen. Understanding how the href works would help.
Thanks!
I have a node project with some simple admin interfaces. One page shows a list of users, it's paginated with a bootstrap paginator and when there's several thousand users the pagination looks like
Here's the code:
<nav>
<div class="text-center">
<ul class="pagination pagination-sm">
<li
<% if(page <= 0) { %>
class="disabled"
<% } %>
><a href="?page=<%= page <= 0 ? 0 : page - 1 %>">«</a></li>
<% for(var i = 0; i < pages; i++) { %>
<li
<% if(page == i) { %>
class="active"
<% } %>
><a href="?page=<%= i %>"><%= i + 1 %></a></li>
<% } %>
<li <% if(page > pages - 1) { %>class="disabled"
<% } %>
><a href="?page=<%= page > pages - 1 ? parseInt(pages) : 1 + parseInt(page) %>">»</a></li>
</ul>
</div>
I'm not an html person. Here are my questions:
1: How does the href ?page=n
work? What's the ?
do? I assume there's logic somewhere that directs the browser to show the new page but I'm not sure where.
2: Is there a good way to add an ellipsis or some other truncated pagination? I suppose I can show ten pages and bookend it with the single page advancers and bookend that with something to show the next/previous ten pages. I'm not entirely sure how to make that happen. Understanding how the href works would help.
Thanks!
Share Improve this question asked Aug 23, 2016 at 14:00 MayNotBeMayNotBe 2,1403 gold badges33 silver badges50 bronze badges1 Answer
Reset to default 3Paginate library takes most of the heavy burden of actually implementing pagination off you. You simply need to calculate three variables: Number of totals items, items per page, and current page number.
var totalItems, itemsPerPage, pageNum;
// calculate the data for above variables and pass them in below method
var pagination = paginate.page(totalItems, itemsPerPage, pageNum);
var paginationHtml = pagination.render({ baseUrl: '/' }); //the link to pass to href, page number will be added as query paramtere to it e.g. /?page=6
paginationHtml
now contains the bootstrap's pagination HTML. Simply pass it as parameter to ejs template and render it:
<%- paginationHtml %>
This one liner will give you the following:
You can change the styling by modifying bootstrap classes for pagination (as done in the example screenshots).
本文标签: javascriptBootstrap pagination in ejs templateStack Overflow
版权声明:本文标题:javascript - Bootstrap pagination in .ejs template - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745575511a2156993.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论