petkopara / PetkoparaCrudGeneratorBundle

Symfony3 CRUD generator bundle with pagination, filter, bulk actions and Twitter bootstrap 3.3.6 features.
MIT License
70 stars 17 forks source link

modifying the Pagination - applying mdb stylesheet #34

Closed ahmed-bhs closed 7 years ago

ahmed-bhs commented 7 years ago

hi , i'm trying to customize another template( material design) to the pagnation system using, but ididn't get enough parameter to change it, the only code i get is in the index.html.twig

<div class="col-md-6 col-md-offset-2 text-right">
     {{ pagerHtml|raw }} 
</div>

can u give me any solution please . sory for my englesh.

ahmed-bhs commented 7 years ago

Hi
I got a solution , for my case i'm using mdb : capture

In Usercontroller.php :

 protected function paginator($queryBuilder, Request $request)
    {
        //sorting
        $sortCol = $queryBuilder->getRootAlias().'.'.$request->get('pcg_sort_col', 'id');

        $queryBuilder->orderBy($sortCol, $request->get('pcg_sort_order', 'desc'));
        // Paginator
        $adapter = new DoctrineORMAdapter($queryBuilder);
        $pagerfanta = new Pagerfanta($adapter);
        $pagerfanta->setMaxPerPage($request->get('pcg_show' , 10));

        try {
            $pagerfanta->setCurrentPage($request->get('pcg_page', 1));
        } catch (\Pagerfanta\Exception\OutOfRangeCurrentPageException $ex) {
            $pagerfanta->setCurrentPage(1);
        }

        $entities = $pagerfanta->getCurrentPageResults();
       $total=iterator_count($entities);

        // Paginator - route generator
        $me = $this;
        $routeGenerator = function($page) use ($me, $request)
        {
            $requestParams = $request->query->all();
            $requestParams['pcg_page'] = $page;
            dump($page);
            dump($requestParams);
            dump( $me->generateUrl('user', $requestParams));
            return $me->generateUrl('user', $requestParams);
        };

        $view = new TwitterBootstrap3View();

$maxPerPage = $pagerfanta->getMaxPerPage();

// 1 by default
$currentPage = $pagerfanta->getCurrentPage();

$nbResults = $pagerfanta->getNbResults();
$currentPageResults = $pagerfanta->getCurrentPageResults();

$haveToPaginate=$pagerfanta->haveToPaginate(); // whether the number of results is higher than the max per page

$hasPreviousPage=$pagerfanta->hasPreviousPage();

$hasNextPage=$pagerfanta->hasNextPage();
$pagin=intval (ceil($nbResults/$maxPerPage));
if ($pagin==0) {
   $pagin=1;
}

        return ['maxPerPage'=>$maxPerPage,'currentPage'=>$currentPage,'nbResults'=>$nbResults,'currentPageResults'=>$currentPageResults,'haveToPaginate'=>$haveToPaginate,'hasPreviousPage'=>$hasPreviousPage,'hasNextPage'=>$hasNextPage,'users'=>  $entities,'pagin'=>$pagin];
    }

In Index.html.twig :

  <div class="pull-right">
<nav>
    <ul class="pagination pg-red">
        <!--Arrow left-->
             {% set var1 = arr.currentPage - 1 %}
        <li class="page-item">
            {% if var1==0 %}<a  class="page-link disabled" aria-label="Previous" >{% else %}
            <a href="?pcg_page={{var1}}" class="page-link" aria-label="Previous">{% endif %}
                <span aria-hidden="true">&laquo;</span>
                <span class="sr-only">Previous</span>
            </a>
        </li>

        <!--Numbers-->
{% for i in 1..arr.pagin %}
    {% if i==arr.currentPage %}<li class="page-item active"><a class="page-link">{{i}}</a></li>{% else %}
  <li class="page-item"><a href="?pcg_page={{i}}" class="page-link">{{i}}</a></li>
 {% endif %}

{% endfor %}
      {% set var = arr.currentPage + 1 %}

        <!--Arrow right-->
        <li class="page-item">
    {% if arr.hasNextPage == true %}
            <a href="?pcg_page={{var}}"class="page-link " aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
                <span class="sr-only">Next</span>
            </a>{% else %}  <a  class="page-link disabled" aria-label="Next">
                <span aria-hidden="true">&raquo;</span>
                <span class="sr-only">Next</span>
            </a>{% endif %}
        </li>
    </ul>
</nav><!-- /#bottom -->

</div>