Skip to content

Instantly share code, notes, and snippets.

@moisessepulveda
Last active March 18, 2021 15:39
Show Gist options
  • Save moisessepulveda/5db03ad972cc695696c9c2b280d56f38 to your computer and use it in GitHub Desktop.
Save moisessepulveda/5db03ad972cc695696c9c2b280d56f38 to your computer and use it in GitHub Desktop.
django tailwind pagination
{% if paginator.num_pages > 1 %}
<div class="flex justify-center">
<div class="flex flex-col items-center my-12">
<div class="flex text-gray-700">
{% if entity.has_previous %}
<a href="?page={{ entity.previous_page_number }}#pagtable"
class="h-12 w-12 mr-1 flex justify-center items-center rounded-full bg-gray-200 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" fill="none"
viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round" class="feather feather-chevron-left w-6 h-6">
<polyline points="15 18 9 12 15 6"></polyline>
</svg>
</a>
{% endif %}
<div class="flex h-12 font-medium rounded-full bg-gray-200">
{% for page in paginator.page_range %}
{% if forloop.last and page != entity.number and paginator.num_pages > 7 %}
{% if entity.next_page_number != paginator.num_pages %}
<div class="w-12 md:flex justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in rounded-full">
<a class=""
href="?page={{ entity.number | add:1 }}#pagtable">...</a>
</div>
{% endif %}
<div class="w-12 md:flex justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in rounded-full">
<a class=""
href="?page={{ paginator.num_pages }}#pagtable">{{ paginator.num_pages }}</a>
</div>
{% endif %}
{% if page == entity.number and page > 7 %}
<li class="w-12 md:flex justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in rounded-full ">
<a class="" href="?page={{ page | add:-1 }}#pagtable">...</a>
</li>
{% endif %}
{% if page < 7 or page == entity.number %}
<a href="?page={{ page }}#pagtable"
class="w-12 md:flex justify-center items-center hidden cursor-pointer leading-5 transition duration-150 ease-in rounded-full {% if page == entity.number %}bg-green-600 text-white{% endif %}">
{{ page }}
</a>
{% endif %}
{% endfor %}
</div>
{% if entity.has_next %}
<a href="?page={{ entity.next_page_number }}#pagtable"
class="h-12 w-12 ml-1 flex justify-center items-center rounded-full bg-gray-200 cursor-pointer">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" fill="none"
viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round"
class="feather feather-chevron-right w-6 h-6">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</a>
{% endif %}
</div>
</div>
</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment