I have an entity “Action” in relation to “User”. Created Admin CRUD controller in SonataAdminBundle. Everything works fine, except that the user filter appears as a drop-down list. I have 8k users and is growing, so you must understand why this is a problem.
I want the custom filter to be text entered and sent to search withLIKE %username%
Now I add user filter as follows: $datagridMapper->add('user').
I know that I can add a filter type and a field type, but I cannot find the correct combination and parameters. Found information about http://sonata-project.org/bundles/doctrine-orm-admin/master/doc/reference/filter_field_definition.html , but still failed.
Final decision
After Alex Togo answered, I used this code:
$datagridMapper->add('user', 'doctrine_orm_callback', array(
'callback' => function($queryBuilder, $alias, $field, $value) {
if (empty($value['value'])) {
return;
}
$queryBuilder->leftJoin(sprintf('%s.user', $alias), 'u');
$queryBuilder->where('u.username LIKE :username');
$queryBuilder->setParameter('username', '%'.$value['value'].'%');
return true;
},
'field_type' => 'text'
))
source
share