Попробуйте это:
protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add("category", 'doctrine_orm_callback', array(
'callback' => function ($queryBuilder, $alias, $field, $value) {
/**
* @var QueryBuilder $queryBuilder
*/
if ($value['value']) {
if ($value['value'] == 0) {
$queryBuilder->andWhere($queryBuilder->expr()->isNull($alias.'.category'));
return true;
} else {
$category = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager')->getReference('AcmeBundle:Category', $value['value']);
$queryBuilder->andWhere($queryBuilder->expr()->eq($alias.'.category', $category));
return true;
}
}
},
'field_type' => 'choice',
'field_options' => array(
'choices' => $this->getCategoryChoices()
),
'label' => 'Category'
));
}
private function getCategoryChoices()
{
$categories = $this->getConfigurationPool()->getContainer()->get('doctrine.orm.entity_manager')->getRepository('AcmeBundle:Category')->findAll();
$choices["0"] = "NULL";
foreach($categories as $category) {
$choices["{$category->getId()}"] = $category->getName();
}
return $choices;
}