Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Sorting #178

@kironet

Description

@kironet

Hi,

Want to move from KnpPaginatorBundle and I'm stuck with sorting.
In KnpPaginatorBundle has this
{{ knp_pagination_sortable(products, 'Price ASC', 'p.price', {'direction': 'asc'}) }}

How can I sort in Pagerfanta?
My repository:

    public function getByCategories(array $categories, $page = 1): Pagerfanta
    {
        $qb = $this->createQueryBuilder('p');
        $qb->leftJoin('p.categories', 'c');
        $qb->where('p.enabled = true');
        $qb->andWhere($qb->expr()->in('c.id', $categories));

        return $this->paginator($qb->getQuery()->useQueryCache(true), $page);
    }
    private function paginator(Query $query, int $page): Pagerfanta
    {
        $paginator = new Pagerfanta(new DoctrineORMAdapter($query));
        $paginator->setMaxPerPage(Product::NUM_ITEMS);
        $paginator->setCurrentPage($page);

        return $paginator;
    }

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions