Closed FredDut closed 4 years ago
'Terminé' is supposed to be selected since you set the operator to 'neq' and the filter value to 'Terminé'. It's expected behavior.
If you want it the other way, you need to set the operator to 'eq' and set the 'En cours' and 'Suspendu' as the value.
$grid->setDefaultFilters(array(
'etat.nom' => ['operator'=>'eq','from' => ['En cours', 'Suspendu]
));
I didn't verify the exact syntax of setting 2 values in the 'from', so please check if it's correct or not
Damned, I didn't thought of 'neq' . The syntax of setting 2 values in the 'from' works fine. Thanks a lot!
I've two entities: Job and Etat The table etat contains only three status:
insert into etat_ values(0,'Terminé');
insert into etat_ values(1,'En cours');
insert into etat values(2,'Suspendu');
There's ManyToOne relation between Etat and Job
@GRID\Column(title="État",field="etat.nom", align="center",filterable=true, filter="select",
selectFrom="source",selectMulti=true,defaultOperator="eq", operatorsVisible=false,groups="index"})
@ORM\ManyToOne(targetEntity="AppBundle\Entity\Etat")
@ORM\JoinColumns({
@ORM\JoinColumn(name="etat", referencedColumnName="id")
})
I want to show a grid filtered by default with "En cours" and "Suspendu", but let the possibility to filter with "Terminé.
In the controller
$source = new Entity('AppBundle:Job', 'index');
$grid = $this->get('grid');
$grid->setDefaultFilters(array(
'etat.nom' => ['operator'=>'neq','from' =>'Terminé']
));
The grid is filtering correctly but "Terminé" is selected in the select of the filter.
Is it a bug?
apy/datagrid-bundle 3.2.0 symfony/symfony v3.4.36