Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 
);
like image 488
rtyshyk Avatar asked Nov 14 '11 11:11

rtyshyk


1 Answers

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';
}
like image 55
Roman Shamritskiy Avatar answered Sep 19 '22 06:09

Roman Shamritskiy