Skip to content

Choose the field to filter not a FilterClass #15

@Charlie-Lucas

Description

@Charlie-Lucas

When you create a widget Filter you can choose a filter in the list but each filter is set for a specific association and a specific field name. So we need to re-create a filter every time we want filter on a property.
For me the best process to generate a filter is:

  1. choose the listing
  2. list fields of the entity listed and select
  3. choose the default filter based on the field : string, onetomany, ... or a specific filter that was created for this type of relation.

Each filter can be define with a list of metadatas to define the relation it can be used:
services.yml

    acme.user_gender_filter:
        class: AcmeBundle\Filter\UserGenderFilter
        parent: victoire_filter.filter.many_to_one_filter
        tags:
            - { name: form.type }
            - { name: victoire_core.filter,  relation: ManyToOne, targetEntity: AcmeBundle\Entity\User}

Book.php

class Book
{
     /**
      * @ORM\ManyToOne(targetEntity="AcmeBundle\Entity\User", inversedBy="books")
      */
     private $author;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $name;
}

Then in this example we can create a filter on a list of books like this:
screen shot 2016-09-08 at 11 11 30

If "Default" filter is the only available filter the select of filters is not display.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions