AliHichem / AliDatatableBundle

Symfony2 Ajax Datagrid Bundle for doctrine2 entities
MIT License
112 stars 72 forks source link

Merge data from two fields. #143

Closed tomwoj6 closed 9 years ago

tomwoj6 commented 9 years ago

Is there any possibility to merge data from 2 fields from db into one field in datatables? Something like that:

 ->setFields(
     array(
              "fielddt" => 'field_db_1 + field_db_2',
               "_identifier_" => 'vac.id')                          
        )

Ofcourse I can achieve this using querybuilder:

 $qb->from("BSHrBundle:Vac", "vac")
       ->leftJoin('x.author', 'author')  
       ->select('x')
       ->addSelect("CONCAT(x.firstname, ' ', x.lastname) as fullUsername");

 $datatable = $this->get('datatable')
                    ->setFields(
                            array(
                                "Column 1 label" => 'fullUsername',
                                "_identifier_" => 'vac.id')
                            )
                    ->setHasAction(FALSE)
                    ->setSearch(TRUE);
  $datatable->getQueryBuilder()->setDoctrineQueryBuilder($qb);

but later I can't search by that field. I am getting this error: [Syntax Error] line 0, col 82: Error: Expected '.' or '(', got 'fullUsername'

Thanks in advance.

AliHichem commented 9 years ago

@tomwoj6 use dt_obj as described in https://github.com/AliHichem/AliDatatableBundle#-custom-renderer