Closed vittore closed 2 years ago
Sure! Here's an example of controller, with list and sort actions:
<?php
class MyController
{
#[Route('list', name: 'foo_list', methods: [Request::METHOD_GET])]
public function lista(Repository $repository, Filter $filter, Request $request): Response
{
if ($filter->saveFilter(FooFilterType::class, 'foo')) {
return $this->redirectToRoute('foo_list');
}
$pagination = $repository->paginate($filter->filter('foo'), $request->query->getInt('page', 1));
return $this->render('foo/list.html.twig', [
'form' => $filter->getFormView('foo'),
'pagination' => $pagination,
]);
}
#[Route('/sort/{field}/{direction}', name: 'foo_sort', requirements: ['direction' => 'ASC|DESC'], methods: [Request::METHOD_GET])]
public function sort(Filter $filter, string $field, string $direction = 'ASC'): Response
{
$filter->sort('foo', $field, $direction);
return $this->redirectToRoute('foo_list');
}
}
The "list" should be already covered in examples ayway. The same examples are showing what to do in templates.
Let me know if you need more info
Perfect. Thanks a lot.
v.
PS: is there any documentation about multi sort?
PS: is there any documentation about multi sort?
Sorry, multi-sorting is not supported
Hi,
is there a simple full code example (controller and template) about sorting? I'm trying to mix:
php bin/console make:crud
Knp\Component\Pager\PaginatorInterface
PUGX\FilterBundle\Filter
The target is a simple, completed, and nice boostrap5 CRUD interface.
Thanks in advance. Vittore.