问题
I need that my custom action button leads to a filtered Sonata List (Curriculum), but I need to use two parameters (Company and External).
Previously, I have been using this approach: Sonata Admin Action Button to Pre Filtered List, but I couldn't manage to use two parameters at the same time.
<a class="btn btn-sm btn-default" href="{{ path('admin_myvendor_mybundle_curriculum_list',{'filter[companies][value]' : object.id }) }}"><i class="fa fa-university"></i> Curriculums </a>
Any idea how to solve this? I thought about creating a controller and using a custom QueryBuilder but I still want to use Sonata list (and without overwriting my default ListMapper in Admin)
回答1:
What you will need to do to achieve this is override the createQuery()
method in your admin.
the tricky part is that the original query for the list uses SELECT DISTINCT
so for each order by that you will add to the query you will need to add the same field to the select statement.
https://github.com/sonata-project/SonataAdminBundle/issues/1548
In one of my bundles i used a workaround to automatically add fields in order by clauses to the select part of the query by extending the ProxyQuery class.
if you want to have a look: https://github.com/blast-project/DoctrinePgsqlBundle/blob/master/Datagrid/ProxyQuery.php the magic happens between line 98 and line 112
来源:https://stackoverflow.com/questions/41443478/custom-action-leading-to-filtered-list-with-multiple-parameters