I have one entity Hike which have relation with another named Department
JavaScript
x
<?php
class Hike
{
private $id;
private $name;
private $description;
/**
* @ORMManyToOne(targetEntity=Department::class, inversedBy="hikes")
* @ORMJoinColumn(nullable=false)
* @AssertNotBlank(message="libdepartmentRequired")
*/
private $department;
// ...
}
JavaScript
<?php
class Department
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMColumn(type="string", length=3)
*/
private $department_code;
/**
* @ORMColumn(type="string", length=255)
*/
private $department_nom;
/**
* @ORMOneToMany(targetEntity="AppEntityHike", mappedBy="department")
*/
private $hikes;
// ...
}
In easyAdmin3 rendering is fine like
But when I sorting by department
I see that easyAdmin3 sort by department’s id, and I would like sorting by department_nom
I saw many solutions but they all using easyAdmin2 and easy_admin.yaml which no longer exists now.
There is a way to achieve that ?
Advertisement
Answer
Use configureCrud. Something like this should do the trick.
JavaScript
public function configureCrud(Crud $crud): Crud
{
return $crud
->setDefaultSort(['departement' => 'DESC'])
;
}
You can also use the filter to get the resultat wanted.