Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I filter several fields in one filter?

Is possible to create search filter to search from not one field, but from CONCAT(name, description) ?

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('search');
}
like image 550
Liutas Avatar asked Jan 31 '13 09:01

Liutas


People also ask

How do I filter multiple columns at the same time?

The easiest way to filter multiple columns in Excel is to use the Advanced Filter function. The following examples show how to use this function in two different scenarios: Filter for rows that meet multiple conditions. Filter for rows that meet one of multiple conditions.

How do I filter multiple columns with one criteria?

1. Enter this formula: =ISERROR(MATCH("Helen",A2:C2,0)) into cell D2, and then drag the fill handle down to the cells to apply this formula, and the FALSE and TRUE displayed into the cells, see screenshot: Note: In the above formula: “Helen” is the criteria that you want to filter rows based on, A2:C2 is the row data.


1 Answers

I found solution with doctrine_orm_callback type

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{


    $datagridMapper
        ->add( 'text', 'doctrine_orm_callback', array(
            'callback' => array($this, 'getSearchFilter'),
            'field_type' => 'text'
        ) );
}

public function getSearchFilter($queryBuilder, $alias, $field, $value) {
    if (!$value['value']) {
        return;
    }

    $exp = new \Doctrine\ORM\Query\Expr();
    $queryBuilder->andWhere($exp->like($exp->concat($alias.'.name', $alias.'.description'), $exp->literal('%' . $value['value'] . '%')));

    return true;
}    
like image 182
Liutas Avatar answered Oct 01 '22 19:10

Liutas