I would like to create a filter where the search would only give me the entries starting with what is searched.
For exemple, I'm searching for a post code starting with "92". With the current filter, it gives me "92000", but also "29200" when I only want the first one.
In SQl it would be "where postcode like $value%" or something like that.
Edit after the 2 first answers:
I tried the custom callback. But the exemple is a for a linked entity displayed as a checked box, and I just want a "where like something%" on a field in the entity. No leftjoin !
Here is my code so far, but I get "Warning: Illegal string offset 'value'"
$this->datagrid->add('postCode', 'doctrine_orm_callback', array(
'callback' => function($queryBuilder, $field, $value) {
if (!$value['value']) {
return;
}
$queryBuilder->andWhere('s.postCode like :value');
$queryBuilder->setParameter('value', $value);
return true;
}
));
The field is 'postCode' in the entity 'Trainer'