Question: I have been looking for hours for a way of setting a condition on the list of items that an APYDataGridBundle grid should return but could not find an answer.

Is there a way to set a DQL Query and pass it to the grid to display the exact query results I want to fetch?

This is the code:

```
public function filteredlistAction(){
    // Create simple grid based on the entity
    $source = new Entity('ACMEBundle:MyEntity');
    // Get a grid instance
    $grid = $this->get('grid');

    // Attach the source to the grid
    $grid->setSource($source);
    ...
    ...

    **$grid->getColumns()->getColumnById('myentity_filter_column')->setData('the exact value I tried to match');**

    // Manage the grid redirection, exports and the response of the controller
    return $grid->getGridResponse('ACMEBundle:MyEntity:index_filteredlist.html.twig');
}

```

Answer: 
You can add a callback (closure or callable) to run before `QueryBuilder` execution - its done like this :

```
$source->manipulateQuery(
    function ($query)
    {
        $query->resetDQLPart('orderBy');
    }
);

$grid->setSource($source);

```

`$query` is an instance of `QueryBuilder` so you can change whatever you need to

[Example taken from docs here](https://github.com/Abhoryo/APYDataGridBundle/blob/master/Resources/doc/grid_configuration/manipulate_query.md)
A more "complicated" query.

```
$estaActivo = 'ACTIVO';
$tableAlias = $source->getTableAlias();
$source->manipulateQuery(
                            function ($query) use ($tableAlias, $estaActivo)
                            {
                                $query->andWhere($tableAlias . '.estado = :estaActivo')
                                      ->andWhere($tableAlias . '.tipoUsuario IN (:rol)')
                                      ->setParameter('estaActivo', $estaActivo)
                                      ->setParameter('rol', array('VENDEDOR','SUPERVISOR'), \Doctrine\DBAL\Connection::PARAM_STR_ARRAY);
                            }
                        );

```

Cheers!