M
M
Maxim2016-02-28 02:21:03
symfony
Maxim, 2016-02-28 02:21:03

How to properly set up range date filter in SonataAdminBundle?

Who is familiar with SonataAdminBundle do not pass by)
There is a filter in the Admin class

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('createdAt', 'doctrine_orm_date_range', array('field_type'=>'sonata_type_date_range_picker',))
                ;
   }

But it does not work, 2 fields appear with From date and End date and with the ability to select a date in the datepicker. After I apply a filter over these fields, it gives out This value is not valid and, accordingly, does not filter anything. As I understand it, it cannot parse the date.
281e3b8e3acc4d0998be31082eb5dd63.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jaxel, 2016-02-29
@maxloyko

This is due to the fact that sonata intl is connected.
We need to make the same format for picker and backend.

->add(
    'createdAt',
    'doctrine_orm_date_range',
    [],
    'sonata_type_date_range_picker',
    [
        'field_options_start' => [
            'format' => 'dd.MM.yyyy'
        ],
        'field_options_end' => [
            'format' => 'dd.MM.yyyy'
        ]
    ]
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question