Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
955 views
in Technique[技术] by (71.8m points)

symfony - 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 
);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...