Sylius Grids come with built-in filters, but there are use-cases where you need something more than basic filter. Grids allow you to define your own filter types!
To add a new filter, we need to create an appropriate class and form type.
src/Grid/Filter/SuppliersStatisticsFilter.php
<?phpnamespaceApp\Grid\Filter;useApp\Form\Type\Filter\SuppliersStatisticsFilterType;useSylius\Bundle\GridBundle\Doctrine\DataSourceInterface;useSylius\Component\Grid\Filtering\ConfigurableFilterInterface;classSuppliersStatisticsFilterimplementsConfigurableFilterInterface{publicfunctionapply(DataSourceInterface $dataSource, $name, $data,array $options = []):void {// Your filtering logic.// $data['stats'] contains the submitted value!// here is an example $queryBuilder = $dataSource->getQueryBuilder(); $queryBuilder->andWhere('stats = :stats')->setParameter(':stats', $data['stats']) ;// For driver abstraction you can use the expression builder. ExpressionBuilder is kind of query builder.// $data['stats'] contains the submitted value!// here is an example $dataSource->restrict($dataSource->getExpressionBuilder()->equals('stats', $data['stats'])); }publicstaticfunctiongetType() :string {return'suppliers_statistics'; }publicstaticfunctiongetFormType() :string {returnSuppliersStatisticsFilterType::class; }}