Sonata admin bundle order

不问归期 提交于 2019-11-27 23:26:27

问题


How to change default entity order in SonataAdminBundle for list action?


answer :) add this to your admin class

protected $datagridValues = array(
    '_page' => 1,
    '_sort_order' => 'DESC', // sort direction 
    '_sort_by' => 'id' // field name 
);

回答1:


You can add another sort order or set a default one via the constructor like this:

public function __construct($code, $class, $baseControllerName)
{
    parent::__construct($code, $class, $baseControllerName);

    if (!$this->hasRequest()) {
        $this->datagridValues = array(
            '_page'       => 1,
            '_sort_order' => 'ASC',      // sort direction
            '_sort_by'    => 'artist_id' // field name
        );
    }
}



回答2:


It is better not to override constructor. But you can override the Admin::configure() method and set some element of the datagridValues array.

See in example:

public function configure()
{
    parent::configure();

    $this->datagridValues['_sort_by']    = 'name';
    $this->datagridValues['_sort_order'] = 'DESC';
}


来源:https://stackoverflow.com/questions/8120787/sonata-admin-bundle-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!