Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Bundles
  4. SonataAdminBundle
  5. Persisting Filters

Persisting Filters

Edit this page

Persisting filters allow your application to save the filters the authenticated user has submitted. Then the saved filters will be reused if the page is displayed again.

Enable Filters Persistence

By default, filters persistence is disabled. You can enable it in your sonata_admin configuration :

1
2
3
4
# config/packages/sonata_admin.yaml

sonata_admin:
    persist_filters: true

Choose the persistence strategy

When you enable the filters persistence by setting persist_filters to true. SonataAdmin will use the default filter persister : Sonata\AdminBundle\Filter\Persister\SessionFilterPersister (which is, by now, the only one provided).

You can implement your own filter persister by creating a new class that implements the Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface interface and registering it as a service. Then the only thing to do is to tell SonataAdmin to use this service as filter persister.

Globally :

1
2
3
4
5
# config/packages/sonata_admin.yaml

sonata_admin:
    persist_filters: true
    filter_persister: filter_persister_service_id

Per Admin :

1
2
3
4
5
6
7
8
9
10
11
# config/services.yaml

services:
    app.admin.user:
        class: App\Admin\UserAdmin
        tags:
            -
                name: sonata.admin
                model_class: App\Entity\User
                manager_type: orm
                filter_persister: filter_persister_service_id

Disable filters persistence for some Admin

When you enable the filters persistence by setting persist_filters to true. All registered Admins will have the feature enabled.

You can disable it per Admin if you want.

1
2
3
4
5
6
7
# config/services.yaml

services:
    app.admin.user:
        class: App\Admin\UserAdmin
        tags:
            - { name: sonata.admin, model_class: App\Entity\User,  manager_type: orm, persist_filters: false }

Note

Both persist_filters and filter_persister can be used globally and per-admin, which provide you the most flexible way to configure this feature.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Symfony Code Performance Profiling

    Symfony Code Performance Profiling

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Peruse our complete Symfony & PHP solutions catalog for your web development needs.

    Version:

    Table of Contents

    • Enable Filters Persistence
    • Choose the persistence strategy
    • Disable filters persistence for some Admin

    Symfony footer

    Avatar of Andrew Tch, a Symfony contributor

    Thanks Andrew Tch for being a Symfony contributor

    1 commit • 66 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony