Skip to content

Commit

Permalink
pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 24, 2024
1 parent d772301 commit 65698ff
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 39 deletions.
51 changes: 51 additions & 0 deletions server/templates/component/pagination.html.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{# require current_page and total_page to work #}

<nav aria-label="...">
<ul class="pagination">
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=1) }}">&laquo;</a>
</li>

{% if current_page > 1 %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=current_page-1) }}">&lt;</a>
</li>
{% endif %}

{% if current_page - 2 > 1 %}
<span class="ms-3 me-3">...</span>
{% endif %}

{% for index in range(max(1, current_page - 2) , min(current_page + 3, total_page + 1)) %}
{% if index == current_page %}
<li class="page-item active">
<a class="page-link"
href="{{ replace_url_query(page=index) }}">{{ index }}</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=index) }}">{{ index }}</a>
</li>
{% endif %}
{% endfor %}

{% if current_page + 3 < total_page + 1 %}
<span class="ms-3 me-3">...</span>
{% endif %}

{% if current_page < total_page %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=current_page + 1) }}">&gt;</a>
</li>
{% endif %}

<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=total_page) }}">&raquo;</a>
</li>
</ul>
</nav>
40 changes: 1 addition & 39 deletions server/templates/list.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -208,44 +208,6 @@
</div>

{% if total_page is defined %}
<div class="row">
<nav aria-label="...">
<ul class="pagination">
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=1) }}">&laquo;</a>
</li>
{% if current_page > 1 %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=current_page-1) }}">&lt;</a>
</li>
{% endif %}
{% for index in range(max(1, current_page - 2) , min(current_page + 3, total_page + 1)) %}
{% if index == current_page %}
<li class="page-item active">
<a class="page-link"
href="{{ replace_url_query(page=index) }}">{{ index }}</a>
</li>
{% else %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=index) }}">{{ index }}</a>
</li>
{% endif %}
{% endfor %}
{% if current_page < total_page %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=current_page + 1) }}">&gt;</a>
</li>
{% endif %}
<li class="page-item">
<a class="page-link"
href="{{ replace_url_query(page=total_page) }}">&raquo;</a>
</li>
</ul>
</nav>
</div>
{% include "component/pagination.html.jinja2" %}
{% endif %}
{% endblock %}

0 comments on commit 65698ff

Please sign in to comment.