Skip to content

Commit

Permalink
feat: add some grid paginator twig templates
Browse files Browse the repository at this point in the history
  • Loading branch information
kbond committed Mar 7, 2024
1 parent cfad537 commit 0c952ef
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions templates/Grid/Pager/_full.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% apply spaceless %}
{% set pager = grid.page %}
{% set input = grid.input %}
{% set window = window|default(4) %}
<ul class="ui-grid-pager-full">
{% if pager.currentPage == 1 %}
<li class="disabled"><span>&lt;</span></li>
{% else %}
<li><a href="{{ input.applyPage(pager.currentPage - 1) }}">&lt;</a></li>
{% endif %}

{% for i in 1..pager.pageCount %}
{% if loop.index == 1 and pager.currentPage != loop.index %}
<li>
<a href="{{ input.applyPage(loop.index) }}">{{ loop.index }}</a>
</li>
{% elseif loop.index == pager.pageCount and pager.currentPage != loop.index %}
<li>
<a href="{{ input.applyPage(loop.index) }}">{{ loop.index }}</a>
</li>
{% elseif 0 == (pager.currentPage - window) - loop.index %} {# dots before #}
<li class="disabled"><span>...</span></li>
{% elseif 0 == (pager.currentPage + window) - loop.index %} {# dots after #}
<li class="disabled"><span>...</span></li>
{% elseif 0 < (pager.currentPage - window) - loop.index %} {# hide all before #}
{% elseif 0 > (pager.currentPage + window) - loop.index %} {# hide all after #}
{% elseif pager.currentPage == loop.index %}
<li class="active">
<span>{{ loop.index }}</span>
</li>
{% else %}
<li>
<a href="{{ input.applyPage(loop.index) }}">{{ loop.index }}</a>
</li>
{% endif %}
{% endfor %}

{% if pager.currentPage < pager.pageCount %}
<li><a href="{{ input.applyPage(pager.currentPage + 1) }}">&gt;</a></li>
{% else %}
<li class="disabled"><span>&gt;</span></li>
{% endif %}
</ul>
{% endapply %}
6 changes: 6 additions & 0 deletions templates/Grid/Pager/_simple.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<ul class="ui-grid-pager-simple">
<li{{ 1 == grid.page.currentPage ? ' class="disabled"' }}><a href="{{ grid.input.applyPage(1) }}">First</a></li>
<li{{ not grid.page.previousPage ? ' class="disabled"' }}><a href="{{ grid.input.applyPage(grid.page.previousPage|default(1)) }}">Previous</a></li>
<li{{ not grid.page.nextPage ? ' class="disabled"' }}><a href="{{ grid.input.applyPage(grid.page.nextPage|default(grid.page.lastPage)) }}">Next</a></li>
<li{{ grid.page.lastPage == grid.page.currentPage ? ' class="disabled"' }}><a href="{{ grid.input.applyPage(grid.page.lastPage) }}">Last</a></li>
</ul>

0 comments on commit 0c952ef

Please sign in to comment.