Custom Action leading to filtered list with multiple parameters?

家住魔仙堡 提交于 2019-12-25 09:21:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!