EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.04k stars 1.02k forks source link

Filter EntityFilter results #3490

Open seb-jean opened 4 years ago

seb-jean commented 4 years ago

This ticket joins an issue: #3476.

It would be great to filter the drop-down list of EntityFilter :

For example :

public function configureFilters(Filters $filters): Filters
{
    return $filters
        ->add(EntityFilter::new('category'))
        ->filterResults(function(QueryBuilder $queryBuilder) {
            // Conditions
        })
    ;
}

Thanks :)

lukasluecke commented 4 years ago

@seb-jean I'll just answer here, to keep the PR clean of off-topic discussion.

The main difference between AssociationField and EntityFilter is, that the autocomplete with all the added complexity of that only exists for the field, not the filter (at least for now). There are also no "custom options" for filters at all, and they are mainly wrappers around a FormType only (since they are only used in the filter form, there is no other "view").

We should still aim to have a similar API (I went for ->modifyQuery now, because you can not only filter, but also change sort etc.), but the implementation will be different (only the part with the query_builder FormType option will be similar). I'll create a PR for the filter later 🙂

seb-jean commented 4 years ago

Thanks @lukasluecke for PR and for the answer :).

mahono commented 1 year ago

Not sure if I should create another ticket: I understand that the filter is very simple. But it would be great if it could at least use the query builder from the related crud (if there is one). I didn't check the code yet, but maybe it is easier to add instead of complex customization.