Last active
September 12, 2018 18:00
-
-
Save jerinisready/3e087a26eecb00f3677e5a27775b14de to your computer and use it in GitHub Desktop.
Django Template Pagination snippet!
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
Showing {{ page_obj.start_index }} to {{ page_obj.end_index }} of {{ page_obj.paginator.count }} entries | |
{% if is_paginated %} | |
<ul class="pagination"> | |
<!-- VERY FIRST --> | |
<li class="first {% if page_obj.number == 1 %} disabled {% endif %} " | |
id="m_table_1_first"> | |
<a href="?page=1"> | |
<i class="la la-angle-double-left"></i> | |
</a> | |
</li> | |
<!-- *VERY FIRST* --> | |
<!-- PREVIOUS --> | |
<li class="previous {% if not page_obj.has_previous %} disabled {% endif %}"> | |
<a href="{% if page_obj.has_previous %}?page={{ page_obj.previous_page_number }}{% else %}javascript:;{% endif %}"> | |
<i class="la la-angle-left"></i> | |
</a> | |
</li> | |
<!-- *PREVIOUS* --> | |
<!-- ... --> | |
{% if page_obj.number > 2 %} | |
<li class="hellip" id="m_table_1_5_before"> | |
<a href="javascript:;" class="page-link"> | |
… | |
</a> | |
</li> | |
{% endif %} | |
<!-- *...* --> | |
{% for i in page_obj.paginator.page_range %} | |
{% if i > page_obj.number|add:'-3' and i < page_obj.number|add:'3' %} | |
<!-- Nearby --> | |
<li class="{% if page_obj.number == i %}active{% endif %}"> | |
<a href="?page={{ i }}">{{ i }}</a> | |
</li> | |
<!-- *Nearby* --> | |
{% endif %} | |
{% endfor %} | |
<!-- ... --> | |
{% if page_obj.paginator.num_pages > page_obj.number|add:'2' %} | |
<li class="hellip" id="m_table_1_5_before"> | |
<a href="javascript:;"> | |
<i class="la">…</i> | |
</a> | |
</li> | |
{% endif %} | |
<!-- *...* --> | |
<!-- NEXT --> | |
<li class="{% if not page_obj.has_next %}disabled{% endif %}"> | |
<a href="{% if page_obj.has_next %}?page={{ page_obj.next_page_number }}{% else %}javascript:;{% endif %}"> | |
<i class="la la-angle-right"></i> | |
</a> | |
</li> | |
<!-- *NEXT* --> | |
<!-- VERY LAST --> | |
<li class="paginate_button page-item last {% if page_obj.paginator.num_pages == page_obj.number %}disabled {% endif %}" > | |
<a href="?page={{page_obj.paginator.num_pages}}" class="page-link"> | |
<i class="la la-angle-double-right"></i> | |
</a> | |
</li> | |
</ul> | |
{% endif %} |
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
<!-- PAGER HERE --> | |
<!-- pass pagination object as 'pager' from context --> | |
<!-- Bootstrap designed --> | |
<center> | |
<ul class="pager pagination"> | |
{% if pager.obj.has_previous %} | |
<li><a href="?p={{ pager.obj.previous_page_number }}">Previous</a></li> | |
{% endif %} | |
<!--for num in pager.main_obj.page_range--> | |
{% for num in pager.range %} | |
<li {% ifequal num pager.obj.number %}class="active"{% endifequal %}> | |
<a href="?p={{ num }}">{{ num }}</a> | |
</li> | |
{% endfor %} | |
{% if pager.obj.has_next %} | |
<li><a href="?p={{ pager.obj.next_page_number }}">Next >></a></li> | |
{% endif %} | |
</ul> | |
</center> |
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
{% if is_paginated %} | |
{# .... **Now the pagination section** .... #} | |
{% if is_paginated %} | |
<div class="pagination"> | |
<span class="page-links"> | |
{% if page_obj.has_previous %} | |
<a href="?page={{ page_obj.previous_page_number }}">previous</a> | |
{% endif %} | |
<span class="page-current"> | |
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}. | |
</span> | |
{% if page_obj.has_next %} | |
<a href="?page={{ page_obj.next_page_number }}">next</a> | |
{% endif %} | |
</span> | |
</div> | |
{% endif %} | |
{% else %} | |
<h3>Oops! Not Available</h3> | |
<p>Will be updated Soon!</p> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment