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 %} |
Updated @ardentsword version to include 'first' and 'last' buttons:
{% trans_default_domain 'EasyAdminBundle' %}
{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %}
<div class="list-pagination">
<div class="list-pagination-counter">
{{ 'paginator.results'|transchoice(paginator.nbResults)|raw }}
</div>
<div class="pager pagination list-pagination-paginator {{ not paginator.hasPreviousPage ? 'first-page' }} {{ not paginator.hasNextPage ? 'last-page' }}">
<a class="btn btn-secondary {{ 1 == paginator.currentPage ? 'disabled' }}"
href="{{ 1 == paginator.currentPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: 1 }) ) }}">
<i class="fa fa-angle-double-left"></i> <span class="btn-label">{{ 'paginator.first'|trans }}</span>
</a>
<a class="btn btn-secondary {{ not paginator.hasPreviousPage ? 'disabled' }}"
href="{{ not paginator.hasPreviousPage ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: paginator.previousPage }) ) }}">
<i class="fa fa-angle-left"></i> <span class="btn-label">{{ 'paginator.previous'|trans }}</span>
</a>
{# 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 ) %}
<a class="btn btn-secondary" href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a>
{% endfor %}
{% endif %}
<a class="btn btn-secondary" class="current" style="background-color: #e3e7ed">{{ paginator.currentPage }}</a>
{% if paginator.currentPage < paginator.nbPages %}
{% for i in range(paginator.currentPage+1, paginator.currentPage + nearbyPagesLimit) if ( i <= paginator.nbPages ) %}
<a class="btn btn-secondary" href="{{ path('easyadmin', _paginator_request_parameters|merge({ page: i }) ) }}">{{ i }}</a>
{% endfor %}
{% endif %}
{# END DISPLAYING PAGE NUMBERS #}
<a class="btn btn-secondary {{ not paginator.hasNextPage ? 'disabled' }}"
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"></i>
</a>
<a class="btn btn-secondary {{ paginator.currentPage == paginator.nbPages ? 'disabled' }}"
href="{{ paginator.currentPage == paginator.nbPages ? '#' : path('easyadmin', _paginator_request_parameters|merge({ page: paginator.nbPages }) ) }}">
<i class="fa fa-angle-double-right"></i> <span class="btn-label">{{ 'paginator.last'|trans }}</span>
</a>
</div>
</div>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ardentsword You can still use the code from @KaiCMueller. You just have to add this css classes (Read here how you can add additional css assets):