简体   繁体   中英

Sonata Admin Bundle loosing filter settings on edit

I created a standard simple admin for some entities, according to the Sonata handbook. The problem is that the configured filter gets lost when editing an enity. Say I have set 3 filter values and then click on an entity to edit it. Neither "Save" nor the action "Back to list" brings me back to the filtered list. Even pagination starts from 1 again.

How can I keep the set filter?

This is an example admin class:

namespace AppBundle\Admin;


use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

/**
 * Description of OrtAdmin
 *
 * @author markus
 */
class OrtAdmin extends AbstractAdmin{
protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
            ->add('name', 'text');

}

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
    $datagridMapper->add('name');
}

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
            ->addIdentifier('name', 'string');

}

//Remove some export formats
public function getExportFormats() {
    return array(
        'csv', 'xls'
    );
}

//No batch actions
public function getBatchActions() {
    $actions = parent::getBatchActions();
    unset($actions['delete']);

    return $actions;
}    
}

Your filter gets lost after leaving the list view. Re-Opening the list (without getting back to the same URL) will always result in your pre-configured filters, which you can define on per-Admin-class.

Simply enable persistent filters per configuration. Please be aware, that those get persisted into your user's session, which mean they will only reset or change if you press the button "reset filters".

You can easily activate the option like this:

sonata_admin:
    persist_filters: true

There is no dedicated documentation, but you can find the option in SonataAdmin Full Configuration Options .

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