Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sonata date range filter

I have a sonata date range filter

protected function configureDatagridFilters(DatagridMapper $filter)
    {
        $now = new \DateTime();
        $filter
            ->add('created_at', 'doctrine_orm_date_range',  array(
                    'label' => 'created_at_long',
                    'input_type' => 'text',
                    'field_options' => array(
                        'widget' => 'single_text'

                    )
                )
            );
    }

If I enter the same date, elements with this date are not returned in my list. Is there a way to tell sonata do not use strict comparaison and use "less than or equal" and "greater than or equal" operators ?

like image 245
debugall Avatar asked Sep 04 '25 04:09

debugall


1 Answers

I think adding a format tag will relax the constraints. Works for (is inclusive) me anyway with the following:

'format' => 'dd/MM/yyyy'

From this currently live/working filter:

->add('someField', 'doctrine_orm_date_range', [], null, ['format' => 'dd/MM/yyyy', 'widget' => 'single_text'])
like image 126
Richard Avatar answered Sep 05 '25 21:09

Richard