简体   繁体   中英

Specify query for datagridfilter sonata

When using the doctrine_orm_model type for the datagridfilter. Is there a way to define a custom query to fetch the possible filter values?

Lets say I do not want to load all the entities for that specific type. I can not find any way to specify a query or something.

Yes you can like this your admin class. Important is 5 parameter, with query builder.

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('modelField', null, [], 'entity', [
            'class' => 'App\Entity\YourModel',
            'choice_label' => 'name', // or something else as label
            'query_builder' => function(YourModelRepository $repository) {
                // return your query builder
            }
        ]
    );     
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM