Created
August 27, 2018 15:10
-
-
Save KaiCMueller/6692ee84f51341acf582e2103f05f3d4 to your computer and use it in GitHub Desktop.
Adding page numbers to EasyAdmin list views
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
{% trans_default_domain 'EasyAdminBundle' %} | |
{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %} | |
{% if paginator.haveToPaginate %} | |
<div class="list-pagination"> | |
<div class="row"> | |
<div class="col-sm-3 hidden-xs list-pagination-counter"> | |
{{ 'paginator.counter'|trans({ '%start%': paginator.currentPageOffsetStart, '%end%': paginator.currentPageOffsetEnd, '%results%': paginator.nbResults})|raw }} | |
</div> | |
<div class="col-xs-12 col-sm-9"> | |
<ul class="pagination list-pagination-paginator {{ 1 == paginator.currentPage ? 'first-page' : '' }} {{ paginator.hasNextPage ? '' : 'last-page' }}"> | |
{% if 1 == paginator.currentPage %} | |
<li class="disabled"> | |
<span> | |
<i class="fa fa-angle-double-left"></i> {{ 'paginator.first'|trans }} | |
</span> | |
</li> | |
{% else %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: 1 }) ) }}"> | |
<i class="fa fa-angle-double-left"></i> {{ 'paginator.first'|trans }} | |
</a> | |
</li> | |
{% endif %} | |
{% if paginator.hasPreviousPage %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.previousPage }) ) }}"> | |
<i class="fa fa-angle-left"></i> {{ 'paginator.previous'|trans }} | |
</a> | |
</li> | |
{% else %} | |
<li class="disabled"> | |
<span> | |
<i class="fa fa-angle-left"></i> {{ 'paginator.previous'|trans }} | |
</span> | |
</li> | |
{% endif %} | |
{# BEGIN DISPLAYING PAGE NUMBERS #} | |
{# the number of pages that are displayed around the active page #} | |
{% set nearbyPagesLimit = 5 %} | |
{% if paginator.currentPage > 1 %} | |
{% for i in range(paginator.currentPage-nearbyPagesLimit, paginator.currentPage-1) if ( i > 0 ) %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
<li> | |
<a class="current">{{ paginator.currentPage }}</a> | |
</li> | |
{% if paginator.currentPage < paginator.nbPages %} | |
{% for i in range(paginator.currentPage+1, paginator.currentPage + nearbyPagesLimit) if ( i <= paginator.nbPages ) %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a> | |
</li> | |
{% endfor %} | |
{% endif %} | |
{# END DISPLAYING PAGE NUMBERS #} | |
{% if paginator.hasNextPage %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nextPage }) ) }}"> | |
{{ 'paginator.next'|trans }} <i class="fa fa-angle-right"></i> | |
</a> | |
</li> | |
{% else %} | |
<li class="disabled"> | |
<span> | |
{{ 'paginator.next'|trans }} <i class="fa fa-angle-right"></i> | |
</span> | |
</li> | |
{% endif %} | |
{% if paginator.currentPage < paginator.nbPages %} | |
<li> | |
<a href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nbPages }) ) }}"> | |
{{ 'paginator.last'|trans }} <i class="fa fa-angle-double-right"></i> | |
</a> | |
</li> | |
{% else %} | |
<li class="disabled"> | |
<span> | |
{{ 'paginator.last'|trans }} <i class="fa fa-angle-double-right"></i> | |
</span> | |
</li> | |
{% endif %} | |
</ul> | |
</div> | |
</div> | |
</div> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated @ardentsword version to include 'first' and 'last' buttons: