Closed kniziol closed 2 years ago
Hi @kniziol! Please, take a look at https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#configure-the-default-ordering-in-the-list-view.
The allowed way to define the sort of an admin list is by configuring AbstractAdmin::$datagridValues
.
I see your changes at #5598, and I think this property must keep their current behavior, overriding any previous configured sort in the query.
IMO, you should allow to override the default sorting by "id" if the custom query defines another field, but keeping the chance to override that default sorting with the configuration provided at $datagridValues['_sort_by']
and $datagridValues['_sort_order']
.
Hi @phansys 🙃
Please, take a look at https://symfony.com/doc/master/bundles/SonataAdminBundle/reference/action_list.html#configure-the-default-ordering-in-the-list-view.
I understand and it works fine, but if you want to do it, let's say, more programmatically, overwritten method is the correct place, I think.
IMO, you should allow to override the default sorting by "id" if the custom query defines another field, but keeping the chance to override that default sorting with the configuration provided at
$datagridValues['_sort_by']
and$datagridValues['_sort_order']
.
So, the sequence should looks like this?
$datagridValues['_sort_by']
and $datagridValues['_sort_order']
are same as default and $this->query->getSortBy()
and $this->query->getSortOrder()
are not equal to null
, use $this->query->getSortBy()
and $this->query->getSortOrder()
$datagridValues['_sort_by']
and $datagridValues['_sort_order']
I'd say, the configuration must respect the following order (the higher order has more priority):
$datagridValues['_sort_by']
and $datagridValues['_sort_order']
.I've made modifications as you proposed. Take a look at 13e3308 commit.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I added the keep label since there is a WIP PR for this issue https://github.com/sonata-project/SonataAdminBundle/pull/5598
Closing this since now there is a configureDefaultSortValues
method which allow to configure the sort dynamically.
Environment
Sonata packages
Symfony packages
PHP version
Subject
There is a bug when custom sorting of list is defined in overwritten
\Sonata\AdminBundle\Admin\AbstractAdmin::createQuery()
method. It does not work.Steps to reproduce
Overwrite
createQuery()
method in your*Admin
class and call thesetSortOrder()
andsetSortBy()
methods on theSonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery
instance to define custom sorting:Expected results
List is sorted by field and with direction defined in overwritten method -
title
andDESC
.Actual results
List is sorted by default field and with default direction -
id
andASC
.