EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Bootstrap Pagination not working

Open rernesto opened this issue 7 years ago • 2 comments

Describe the bug I am using KNP Paginator on one of my content pages. Also I tried with plain pagination examples from Bootstrap website and didn't work. SO i think is related to Bootstrap CSS styles.

To Reproduce

{% extends easyadmin_config('design.templates.layout') %}
{% block body_class 'page-content page-content-with-padding' %}
{% block main %}
<!-- Pagination -->
    {{ knp_pagination_render(bibleVerses) }}
{% endblock %}

Knp Paginator config:

knp_paginator:
    template:
        pagination: '@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'

Or you can try with

<nav aria-label="...">
  <ul class="pagination">
    <li class="page-item disabled">
      <span class="page-link">Previous</span>
    </li>
    <li class="page-item"><a class="page-link" href="#">1</a></li>
    <li class="page-item active">
      <span class="page-link">
        2
        <span class="sr-only">(current)</span>
      </span>
    </li>
    <li class="page-item"><a class="page-link" href="#">3</a></li>
    <li class="page-item">
      <a class="page-link" href="#">Next</a>
    </li>
  </ul>
</nav>

(OPTIONAL) Additional context Resulting in something like this :'( Screenshot from 2019-04-27 15-30-07

rernesto avatar Apr 27 '19 19:04 rernesto

@rernesto I'm really sorry but we can't help you with this problem. This bundle uses PagerFanta paginator ... so we don't provide any integration with other paginators, such as the KnpPaginator you are using.

javiereguiluz avatar Apr 28 '19 10:04 javiereguiluz

@javiereguiluz Thanks, solved so far creating my own view for pagerfanta. Just created my own paginator changing the original paginator.html.twig where the href attribute it's generated.

...
...path('easyadmin')...
...

to

...
...path(app.request.attributes.get('_route')...
...

Added this to my content view:

{% extends easyadmin_config('design.templates.layout') %}
{% block body_class 'page-content page-content-with-padding' %}

{% set _request_parameters = app.request.query.all|merge(app.request.attributes.get('_route_params'))|merge(_request_parameters|default({}))|merge({
    action: app.request.get('action'),
    menuIndex: app.request.get('menuIndex'),
    submenuIndex: app.request.get('submenuIndex'),
    page: app.request.get('page', 1),
    referer: null
}) %}

...

{% block content_footer %}
    {% block paginator %}
        {% include 'paginator.html.twig' %}
    {% endblock paginator %}
{% endblock %}
...
class HomeController extends BaseController
{
...
/**
     * @Route("/home", name="home_home")
     */
    public function homeAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();

        $qb = $em->getRepository(BibleText::class)
            ->createQueryBuilder('bt');

        $qb->where($qb->expr()->eq('bt.chapterNumber', 1))
            ->andWhere($qb->expr()->lt('bt.verseNumber', 4))
            ->innerJoin('bt.book', 'bb')
            ->innerJoin('bt.version', 'bv');

        $bibleVerses  = $this->get('easyadmin.paginator')->createOrmPaginator(
            $qb, $request->query->getInt('page', 1), 9
        );

        return $this->render(
            'home/home.html.twig', [
                'browserForm' => $this->getBrowserForm([])->createView(),
                'searchForm' => $this->getSearchForm([])->createView(),
                'summaryForm' => $this->getSummaryForm([])->createView(),
                'paginator' => $bibleVerses
            ]
        );
    }
...
}

So far this works.

rernesto avatar Apr 29 '19 16:04 rernesto