Last active
November 19, 2020 07:36
-
-
Save mysiar/c8595c29b7c4321c26138d2d9d5f10be to your computer and use it in GitHub Desktop.
Pagination for EasyAdmin
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
{# tested with 2.3.5 #} | |
{% trans_default_domain 'EasyAdminBundle' %} | |
{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %} | |
{% if paginator.haveToPaginate %} | |
<div class="list-pagination"> | |
<div class="list-pagination-counter"> | |
{{ 'paginator.counter'|trans({ '%start%': paginator.currentPageOffsetStart, '%end%': paginator.currentPageOffsetEnd, '%results%': paginator.nbResults})|raw }} {{ 'easy_admin.results'|trans }} | |
</div> | |
<nav class="pager list-pagination-paginator {{ not paginator.hasPreviousPage ? 'first-page' }} {{ not paginator.hasNextPage ? 'last-page' }}"> | |
<ul class="pagination list-pagination-paginator {{ 1 == paginator.currentPage ? 'first-page' : '' }} {{ paginator.hasNextPage ? '' : 'last-page' }}"> | |
<li class="page-item {{ not paginator.hasPreviousPage ? 'disabled' }}"> | |
<a class="page-link" | |
href="{{ not paginator.hasPreviousPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: 1 }) ) }}"> | |
<i class="fa fa-angle-double-left mx-1"></i><span class="btn-label">{{ 'paginator.first'|trans }}</span> | |
</a> | |
</li> | |
<li class="page-item {{ not paginator.hasPreviousPage ? 'disabled' }}"> | |
<a class="page-link" | |
href="{{ not paginator.hasPreviousPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: paginator.previousPage }) ) }}"> | |
<i class="fa fa-angle-left mx-1"></i> <span class="btn-label">{{ 'paginator.previous'|trans }}</span> | |
</a> | |
</li> | |
{# BEGIN DISPLAYING PAGE NUMBERS #} | |
{# the number of pages that are displayed around the active page #} | |
{% set nearbyPagesLimit = 3 %} | |
{% if paginator.currentPage > 1 %} | |
{% for i in range(paginator.currentPage-nearbyPagesLimit, paginator.currentPage-1) %} | |
{% if ( i > 0 ) %} | |
<li class="page-item"> | |
<a class="page-link" | |
href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}"> | |
<span class="btn-label">{{ i }}</span> | |
</a> | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% endif %} | |
<li class="page-item"> | |
<a class="page-link current" style="color: red">{{ paginator.currentPage }}</a> | |
</li> | |
{% if paginator.currentPage < paginator.nbPages %} | |
{% for i in range(paginator.currentPage+1, paginator.currentPage + nearbyPagesLimit) %} | |
{% if ( i <= paginator.nbPages ) %} | |
<li class="page-item"> | |
<a class="page-link" | |
href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}"> | |
<span class="btn-label">{{ i }}</span> | |
</a> | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% endif %} | |
{# END DISPLAYING PAGE NUMBERS #} | |
<li class="page-item {{ not paginator.hasNextPage ? 'disabled' }}"> | |
<a class="page-link" | |
href="{{ not paginator.hasNextPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nextPage }) ) }}"> | |
<span class="btn-label">{{ 'paginator.next'|trans }}</span> <i class="fa fa-angle-right mx-1"></i> | |
</a> | |
</li> | |
<li class="page-item {{ not paginator.hasNextPage ? 'disabled' }}"> | |
<a class="page-link" | |
href="{{ not paginator.hasNextPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nbPages }) ) }}"> | |
<span class="btn-label">{{ 'paginator.last'|trans }}</span><i class="fa fa-angle-double-right"></i> | |
</a> | |
</li> | |
</ul> | |
</nav> | |
</div> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment