-
Notifications
You must be signed in to change notification settings - Fork 341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example needed on custom filtering/sorting #25
Comments
I'm looking for it. This is a plus over PagerFanta |
sorry, hope to cover it for friday |
for a start: https://knplabs.com/en/blog/knp-paginator-reborn |
cool! |
Hi, what about this issue? It would be great to have an example of filtering. |
hm, will take a look today ;) |
well, there are 2 ways to do it,
and filter selection which would be controlled by javascript to trigger generated urls. But in overall, if making those abstract, it would be hard to customize, for example have AND or OR filters. So my advice is to have it in the controller, etc based on query parameters, modify the query. and in template just merge the route parameters for new urls, like pagination template does. This way you would be able to achieve more custom results, which in general I do not see the point to abstract, or make it a part of paginator. Sorting is more predictable. |
Thank you! I think I'll use query params and modify the query in the controller |
What about the status of that filtering feature ? |
Still waiting for it! |
any update? |
👍 |
Any update on this? 👍 |
Anybody knows how to use filters? |
there is no general way since knp paginator supports different kinds of providers for pagination to be built. If you are only using Doctrine ORM in our company we use https://github.com/DATA-DOG/DataDogPagerBundle there you can easily customize filters in pragmatic way. |
@l3pp4rd From what I can see DataDogPagerBundle doesn't rely on Doctrine Paginator component, but does simple |
@lokhman right, in complex cases you need custom count. we do not make collection joins for that reason, though there is only a single class which may be customized in such cases. for our needs it serves very well. |
It's possioble to implement filters with form component and query builder modifications after submission. You can use this wrapper for KnpPaginator https://github.com/deejff/DataGridBundle to apply this approach. |
I know that this topic outdated, but I was looking for an example implementation of filtering using the KnpPaginatorBundle and I could not find any. Then I finally find sollution by myself. Filtering works only with Query Object. Here is the example:
And render filtration in TWIG:
I hope that this sample implementation of filtering will be convenient for someone. |
Hello @Mateuszry Do you have any idea how to control the filters created by this function? For example controlling the comparison operator (=, <>, >, <, LIKE) ? |
@amiriskander I'm glad I could help! I'm not sure if this is the answer to your question, because I haven't used this since the publication of the previous post, but if you want to use operator |
Maybe try this bundle? https://github.com/lexik/LexikFormFilterBundle |
Bonjour , voici mon contrôleur: j'ai une erreur que listprojets not find, public function research(Request $request, LesProjetsRepository $LesProjetsRepository)
{
$searchForm = $this->createForm(ResearchType::class);
$filtre1 = $request->query->getAlnum('caracteristiques');
$filtre2 = $request->query->getAlnum('filtre2');
if ( $filtre1 && $filtre2 ) {
$motcle= $request->get('motcle');
$this->log->error('test1');
if (!empty($motcle)) {
$repo = $this->getDoctrine()->getRepository(LesProjets::class);
$this->log->error('test5');
$listprojets = $repo->findProjetsByName($motcle);
}
}
return $this->render('research/index.html.twig', [
'search_form' => $searchForm->createView(),
'listProjets' => $listprojets,
]);
} |
I have a problem on my filter.
But in my view when I try to filter then it doesn't seems to work. I wrote that : In the url it returns "http://myUrl/?filterField=article.title&filterValue=japan" but the articles displayed are still the same. |
I have the same problem.. There is a function, but how to use it is not clear.. have you solved this issue? |
Let me rewrite your example: public function index(Request $request, ArticleRepository $repo, PaginatorInterface $paginator) {
$searchForm = $this->createForm(SearchType::class);
$searchForm->handleRequest($request);
$articles= $repo->findAll();
$filteredArticles = $paginator->paginate(
$articles, // <-------------- THIS IS JUST WRONG. PLEASE READ THE DOCUMENTATION
$request->query->getInt('page', 1),
10,
);
return $this->render('default/home.html.twig', [
'articles' => $filteredArticles
]);
} |
Strange, but your code works for me (sorting and pagination)... |
In the README, there is mention of the ability to add custom filtering and sorting based on the request parameters.
It might be worthwhile adding an example or two of how to use custom filtering and sorting with the PaginatorBundle.
The text was updated successfully, but these errors were encountered: