From eb233a125ccc455e8f90bdeed4e572aff862f4a2 Mon Sep 17 00:00:00 2001 From: Camille Simiand <camille.simiand@tetras-libre.fr> Date: Fri, 21 Jan 2022 10:38:28 +0100 Subject: [PATCH] Previous and Next buttons disabled on first or last page --- config/packages/knp_paginator.yaml | 8 +++ config/packages/paginator.yaml | 13 ---- .../pagination/customized_paginator.html.twig | 65 +++++++++++++++++++ 3 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 config/packages/knp_paginator.yaml delete mode 100644 config/packages/paginator.yaml create mode 100644 templates/pagination/customized_paginator.html.twig diff --git a/config/packages/knp_paginator.yaml b/config/packages/knp_paginator.yaml new file mode 100644 index 0000000..210dd6c --- /dev/null +++ b/config/packages/knp_paginator.yaml @@ -0,0 +1,8 @@ +knp_paginator: + page_range: 3 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6) + default_options: + page_name: page # page query parameter name + template: + pagination: 'pagination/customized_paginator.html.twig' # sliding pagination controls template + sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template + filtration: '@KnpPaginator/Pagination/filtration.html.twig' \ No newline at end of file diff --git a/config/packages/paginator.yaml b/config/packages/paginator.yaml deleted file mode 100644 index 6b7060c..0000000 --- a/config/packages/paginator.yaml +++ /dev/null @@ -1,13 +0,0 @@ -knp_paginator: - page_range: 3 # number of links showed in the pagination menu (e.g: you have 10 pages, a page_range of 3, on the 5th page you'll see links to page 4, 5, 6) - default_options: - page_name: page # page query parameter name - sort_field_name: sort # sort field query parameter name - sort_direction_name: direction # sort direction query parameter name - distinct: true # ensure distinct results, useful when ORM queries are using GROUP BY statements - filter_field_name: filterField # filter field query parameter name - filter_value_name: filterValue # filter value query parameter name - template: - pagination: '@KnpPaginator/Pagination/bootstrap_v5_pagination.html.twig' # sliding pagination controls template - sortable: '@KnpPaginator/Pagination/sortable_link.html.twig' # sort link template - filtration: '@KnpPaginator/Pagination/filtration.html.twig' \ No newline at end of file diff --git a/templates/pagination/customized_paginator.html.twig b/templates/pagination/customized_paginator.html.twig new file mode 100644 index 0000000..a7a6b97 --- /dev/null +++ b/templates/pagination/customized_paginator.html.twig @@ -0,0 +1,65 @@ +{% if pageCount > 1 %} + <nav> + {% set classAlign = (align is not defined) ? '' : align=='center' ? ' justify-content-center' : (align=='right' ? ' justify-content-end' : '') %} + {% set classSize = (size is not defined) ? '' : size=='large' ? ' pagination-lg' : (size=='small' ? ' pagination-sm' : '') %} + <ul class="pagination{{ classAlign }}{{ classSize }}"> + + {% if previous is defined %} + <li class="page-item"> + <a class="page-link" rel="prev" href="{{ path(route, query|merge({(pageParameterName): previous})) }}">«</a> + </li> + {% endif %} + + {% if startPage > 1 %} + <li class="page-item"> + <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): 1})) }}">1</a> + </li> + {% if startPage == 3 %} + <li class="page-item"> + <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): 2})) }}">2</a> + </li> + {% elseif startPage != 2 %} + <li class="page-item disabled"> + <span class="page-link">…</span> + </li> + {% endif %} + {% endif %} + + {% for page in pagesInRange %} + {% if page != current %} + <li class="page-item"> + <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): page})) }}">{{ page }}</a> + </li> + {% else %} + <li class="page-item active"> + <span class="page-link">{{ page }}</span> + </li> + {% endif %} + + {% endfor %} + + {% if pageCount > endPage %} + {% if pageCount > (endPage + 1) %} + {% if pageCount > (endPage + 2) %} + <li class="page-item disabled"> + <span class="page-link">…</span> + </li> + {% else %} + <li class="page-item"> + <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): (pageCount - 1)})) }}">{{ pageCount -1 }}</a> + </li> + {% endif %} + {% endif %} + <li class="page-item"> + <a class="page-link" href="{{ path(route, query|merge({(pageParameterName): pageCount})) }}">{{ pageCount }}</a> + </li> + {% endif %} + + {% if next is defined %} + <li class="page-item"> + <a class="page-link" rel="next" href="{{ path(route, query|merge({(pageParameterName): next})) }}">»</a> + </li> + {% endif %} + </ul> + </nav> +{% endif %} -- GitLab