Skip to content

Commit

Permalink
Remove reference to old TextFilterType and NumberFilterType classes (#84
Browse files Browse the repository at this point in the history
)

* Remove reference to old TextFilterType and NumberFilterType classes

* Update filters.md
  • Loading branch information
alexandre-castelain authored May 13, 2024
1 parent 04b404a commit dca8c58
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions docs/src/docs/components/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ To add a filter, use the data table builder's `addFilter()` method:
```php
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\NumberFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\NumericFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\DateTimeFilterType;

class UserDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addFilter('id', NumberFilterType::class)
->addFilter('name', TextFilterType::class)
->addFilter('id', NumericFilterType::class)
->addFilter('name', StringFilterType::class)
->addFilter('createdAt', DateTimeFilterType::class)
;
}
Expand Down Expand Up @@ -62,9 +62,9 @@ This is the type that defines all the required options, such as `label`, `form_t

::: danger This is not recommended: do _not_ use PHP inheritance!
```php
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;

class PhoneNumberFilterType extends TextFilterType
class PhoneNumberFilterType extends StringFilterType
{
}
```
Expand All @@ -73,13 +73,13 @@ class PhoneNumberFilterType extends TextFilterType
::: tip This is recommended: provide parent using the `getParent()` method
```php
use Kreyu\Bundle\DataTableBundle\Filter\Type\AbstractFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;

class PhoneNumberFilterType extends AbstractFilterType
{
public function getParent(): ?string
{
return TextFilterType::class;
return StringFilterType::class;
}
}
```
Expand Down Expand Up @@ -182,19 +182,19 @@ class CustomFilterType extends AbstractFilterType implements FilterHandlerInterf
## Filter type extensions

Filter type extensions allows modifying configuration of the existing filter types, even the built-in ones.
Let's assume, that we want to [change default operator](#changing-default-operator) of [`TextFilterType`](#)
Let's assume, that we want to [change default operator](#changing-default-operator) of [`StringFilterType`](#)
to `Operator::Equals`, so it is not necessary to pass `default_operator` option for each filter using this type.

Filter type extensions are classes that implement [`FilterTypeExtensionInterface`](https://github.com/Kreyu/data-table-bundle/blob/main/src/Filter/Extension/FilterTypeExtensionInterface.php).
However, it's better to extend from the [`AbstractFilterTypeExtension`](https://github.com/Kreyu/data-table-bundle/blob/main/src/Column/Extension/AbstractColumnTypeExtension.php):

```php
use Kreyu\Bundle\DataTableBundle\Filter\Extension\AbstractFilterTypeExtension;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;
use Kreyu\Bundle\DataTableBundle\Filter\Operator;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DefaultOperatorTextFilterTypeExtension extends AbstractFilterTypeExtension
class DefaultOperatorStringFilterTypeExtension extends AbstractFilterTypeExtension
{
public function configureOptions(OptionsResolver $resolver): void
{
Expand All @@ -203,7 +203,7 @@ class DefaultOperatorTextFilterTypeExtension extends AbstractFilterTypeExtension

public static function getExtendedTypes(): iterable
{
return [TextFilterType::class];
return [StringFilterType::class];
}
}
```
Expand Down Expand Up @@ -309,22 +309,22 @@ readonly class Book
}
```

If we use a [TextFilterType](#) on the `isbn` column, the filter will perform partial matching (`LIKE %value%`),
If we use a [StringFilterType](#) on the `isbn` column, the filter will perform partial matching (`LIKE %value%`),
because the filter type has `default_operator` option set to `Operator::Contains`.
In this case, we want to perform exact matching, therefore, we have to change this option value to `Operator::Equals`:

```php
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;
use Kreyu\Bundle\DataTableBundle\Filter\Operator;

class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addFilter('isbn', TextFilterType::class, [
->addFilter('isbn', StringFilterType::class, [
'default_operator' => Operator::Equals,
])
;
Expand Down Expand Up @@ -353,15 +353,15 @@ By default, operator selector is **not** visible. To change that, use `operator_
```php
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\TextFilterType;
use Kreyu\Bundle\DataTableBundle\Bridge\Doctrine\Orm\Filter\Type\StringFilterType;
use Kreyu\Bundle\DataTableBundle\Filter\Operator;

class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder
->addFilter('isbn', TextFilterType::class, [
->addFilter('isbn', StringFilterType::class, [
'operator_visible' => true,
])
;
Expand Down

0 comments on commit dca8c58

Please sign in to comment.