简体   繁体   English

Sonata Admin Bundle在编辑时失去过滤器设置

[英]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. 假设我设置了3个过滤器值,然后单击一个实体进行编辑。 Neither "Save" nor the action "Back to list" brings me back to the filtered list. “保存”和“返回列表”操作都无法将我带回到已过滤列表。 Even pagination starts from 1 again. 甚至分页从1开始。

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. 重新打开列表(不返回相同的URL)将始终生成您预先配置的过滤器,您可以在每个管理员级别上定义这些过滤器。

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 . 没有专门的文档,但是您可以在SonataAdmin完整配置选项中找到该选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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