简体   繁体   中英

Sonata admin bundle order

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 ); 

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';
}

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
        );
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM