-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow Sonata Autocomplete to use advanced filters #6300
Comments
@kirya-dev you are totally right - I must have had brain damage that day and confused advanced filters with what I had in mind :) Either way - let me rephrase, what I would like to achieve:
Of course I can achieve the same by adding multiple filters:
but from usability - it would be better in my opinion to have one filter with ability to select property being searched. Does this explaination clarifies it? |
First solution override callback. So $datagridMapper->add(
'user',
ModelAutocompleteFilter::class,
['show_filter' => true,],
null,
[
'property' => 'username',
'minimum_input_length' => 1,
'callback' => static function (AdminInterface $admin, string $property, $searchText) {
$datagrid = $admin->getDatagrid();
if (is_numeric($searchText)) {
$property = 'id';
} elseif (str_contains($searchText, '@')) {
$property = 'email';
} else {
$property = 'username';
}
$datagrid->setValue($datagrid->getFilter($property)->getFormName(), null, $searchText);
}
]
); Second solution is create custom template for autocomplete with radio button to select field for search. Also override callback. Third solution is use some prefix: Code: $datagridMapper->add(
'user',
ModelAutocompleteFilter::class,
['show_filter' => true,],
null,
[
'property' => 'username',
'minimum_input_length' => 1,
'callback' => static function (AdminInterface $admin, string $property, $searchText) {
$datagrid = $admin->getDatagrid();
$searchTextParts = explode(':', $searchText);
if (count($searchTextParts) === 2 && in_array($searchTextParts[0], ['id', 'email', 'username'])) {
[$property, $searchText] = $searchTextParts;
}
$datagrid->setValue($datagrid->getFilter($property)->getFormName(), null, $searchText);
}
]
); |
@kirya-dev great idea 🥇 |
Close issue? |
The third example could be a great addition to our docs, wdyt @sonata-project/contributors ? IMO it could fit under the cookbook section. It can also be improved to accept multiple conditions (similar to what you can do with the github search box) |
It would be great to add option to pass select advanced filter option with autocomplete ajax requests (get-autocomplete-items).
Currently selected advanced filter is not passed to ajax controller causing it to not filter according to setup.
In this case I have selected (not equals), but it still works as "equals"
https://ss.codeone.pl/ss-2020-08-20_14-09-55-1597925395.png
The text was updated successfully, but these errors were encountered: