I've got a field 'shopSurface' which is nullable and not required.
In EA I added a NumericFilter:
NumericFilter::new('shopSurface', 'shop_surface')
.
If I want all the entries which have not shopSurface
I look for equal to
and I leave empty the field but nothing appear, the list is empty while I have some.
Do you know a way to make it appear ?
EDIT
This is how I did :
public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$alias = $filterDataDto->getEntityAlias();
$property = $filterDataDto->getProperty();
$comparison = $filterDataDto->getComparison();
$parameterName = $filterDataDto->getParameterName();
$parameter2Name = $filterDataDto->getParameter2Name();
$value = $filterDataDto->getValue();
$value2 = $filterDataDto->getValue2();
if (ComparisonType::BETWEEN === $comparison) {
$queryBuilder->andWhere(sprintf('%s.%s BETWEEN :%s and :%s', $alias, $property, $parameterName, $parameter2Name))
->setParameter($parameterName, $value)
->setParameter($parameter2Name, $value2);
} else {
$queryBuilder->andWhere(sprintf('%s.%s %s :%s', $alias, $property, $comparison, $parameterName))
->setParameter($parameterName, $value);
}
if (ComparisonType::EQ === $comparison && '' === $value){
$queryBuilder->andWhere(sprintf('%s IS NULL', $alias));
}
}
CodePudding user response:
You have 2 solutions :
- Add a NullFilter in addition to your NumericFilter to show null values (all built-in filters are avalables here)
OR
- Add your custom filter like that (doc here).
If you need some help do not hesitate.