Skip to content

Commit 7878100

Browse files
author
Aitor Brazaola
committed
Custom list filter documentation.
1 parent b608e9f commit 7878100

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

docs/custom_list_filter.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
A list filter is an implementation that defines how an a filter input has to be rendered. This works together with the
44
`AdminRepository` that receives the submitted form that was built using list filter types.
55

6+
Using filters, you can implement customized search based on any field of your entities, although those already
7+
provided `text` and `date` may be enough for most project, perhaps you will need to customize or create more complex
8+
filters for your project specific business logic.
9+
610
1. Create a new class implementing `LIN3S\AdminBundle\Configuration\Type\ListFilterType`
711
1. Add the class to Dependency Container with `lin3s_admin.list_filter_type` tag name and the desired alias.
812
1. Reference the created service with the alias in the property `type` of list > filters > field_name of your `admin.yml`
913

1014
## Render function
1115

12-
>TODO
16+
You can handle the header representation of the row within this function, these are the parameters available:
17+
* filter: A `ListFilter` entity of the filter.
18+
* currentValue: The value to be filtered.
19+
* options: An array of options.
20+
21+
Text filter example:
22+
23+
```php
24+
$attributes = $currentValue !== null ? ' value="' . $currentValue . '"' : '';
25+
26+
foreach ($options['attrs'] as $attrName => $attr) {
27+
$attributes .= ' ' . $attrName . '="' . $attr . '"';
28+
}
29+
30+
return sprintf('<input %s type="text" data-filter-field="%s">', $attributes, $filter->field());
31+
```
32+
33+

0 commit comments

Comments
 (0)