SearchFilterType
The SearchFilterType
represents a special filter that is rendered on the outside of filtering form as a search input.
Adding the search handler
Instead of using this filter, you can use the setSearchHandler()
method:
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;
class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder->setSearchHandler(function (ProxyQueryInterface $query, string $search) {
// ...
});
}
}
Defining a search handler automatically adds search filter.
To disable this behavior, use the setAutoAddingSearchFilter()
method:
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;
class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
$builder->setAutoAddingSearchFilter(false);
}
}
To override configuration of the automatically added filter, you can add search filter manually with the same name:
use Kreyu\Bundle\DataTableBundle\DataTableBuilderInterface;
use Kreyu\Bundle\DataTableBundle\Type\AbstractDataTableType;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;
use Kreyu\Bundle\DataTableBundle\Filter\Type\SearchFilterType;
class ProductDataTableType extends AbstractDataTableType
{
public function buildDataTable(DataTableBuilderInterface $builder, array $options): void
{
// Set "__search" as filter name or use constant:
$builder->addFilter(DataTableBuilderInterface::SEARCH_FILTER_NAME, SearchFilterType::class, [
// ...
]);
}
}
Options
handler
- type:
callable
Sets callable that operates on the query passed as a first argument:
use Kreyu\Bundle\DataTableBundle\Filter\Type\SearchFilterType;
use Kreyu\Bundle\DataTableBundle\Query\ProxyQueryInterface;
$builder
->addFilter('search', SearchFilterType::class, [
'handler' => function (ProxyQueryInterface $query, string $search): void {
// ...
},
])
Inherited options
label
- type:
null
,false
,string
orSymfony\Component\Translation\TranslatableInterface
- default:
null
Sets the label that will be used when rendering the filter.
When value is null
, a sentence cased filter name is used as a label, for example:
Filter name | Guessed label |
---|---|
name | Name |
firstName | First name |
label_translation_parameters
- type:
array
- default:
[]
Sets the parameters used when translating the label
option.
translation_domain
- type:
false
orstring
- default:
'KreyuDataTable'
Sets the translation domain used when translating the translatable filter values.
Setting the option to false
disables translation for the filter.
query_path
- type:
null
orstring
- default:
null
the query path is guessed from the filter name
Sets the path used in the proxy query to perform the filtering on.
form_type
- type:
string
- default:
'Symfony\Component\Form\Extension\Core\Type\TextType'
This is the form type used to render the filter value field.
form_options
- type:
array
- default:
[]
This is the array that's passed to the form type specified in the form_type
option.
operator_form_type
- type:
string
- default:
'Kreyu\Bundle\DataTableBundle\Filter\Form\Type\OperatorType'
This is the form type used to render the filter operator field.
operator_form_options
- type:
array
- default:
[]
This is the array that's passed to the form type specified in the operator_form_type
option.
operator_selectable
- type:
bool
- default:
false
Determines whether the operator can be selected by the user.
default_operator
- type:
Kreyu\Bundle\DataTableBundle\Filter\Operator
- default:
Kreyu\Bundle\DataTableBundle\Filter\Operator::Equals
Determines a default operator for the filter.