通过简单的管理,您可以在一个字段上对列表进行排序.
Symfony - Easy Admin v2: 排序实体列表
但是有没有办法对我的列表的多个字段进行排序?
您可以按照
此处所述覆盖createListQueryBuilder
或createSearchQueryBuilder
执行此操作。
例:
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null)
{
/* @var EntityManager */
$em = $this->getDoctrine()->getManagerForClass($this->entity['class']);
/* @var QueryBuilder */
$queryBuilder = $em->createQueryBuilder()
->select('entity')
->from($this->entity['class'], 'entity')
;
if (!empty($dqlFilter)) {
$queryBuilder->andWhere($dqlFilter);
}
$queryBuilder->addOrderBy('entity.status', 'ASC');
$queryBuilder->addOrderBy('entity.createdAt', 'DESC');
return $queryBuilder;
}