Symfony 5 Search on a DateTimeColumn datatables

I am using Omines Symfony DataTable Bundle https://omines.github.io/datatables-bundle/#doctrine-orm to organize my event table.

I am unable to search on my "Début" and "Fin" columns which are of type Datetime Column. I’m guessing because since these are DateTime objects I’m guessing it can’t find a match.

mytable

If I type "08/19/2020" it doesn’t find any results for me.

Here: https://datatables.net/forums/discussion/44218/how-do-i-search-on-a-datetime-column it advises to format the date on the server side, so I tried that (of course j ‘ve installed the doctrine extensions to be able to use date_format):

->createAdapter(ORMAdapter::class, [
    'entity' => Event::class,
    'query' => function (QueryBuilder $builder) use ($eventStatus) {
        $builder
            ->select('e')    
            ->addSelect('DATE_FORMAT(e.startDate, "%d/%m/%Y")')
            ->addSelect('ca')
            ->addSelect('ci')
            ->addSelect('u')  
            ->from(Event::class, 'e')
            ->join('e.category', 'ca')
            ->join('e.city', 'ci')
            ->join('e.user', 'u')
            ->andWhere('e.status = :status')
            ->setParameter('status', $eventStatus)
            ->orderBy('e.id', 'DESC')
        ;
    },
])

I also changed my dateStart column to TextColumn:

->add('startDate', TextColumn::class, ['label' => 'Début', 'field' => 'e.startDate', 'render' => function($value, $context) {
    return sprintf(
        '%s<br>
        %s',
        $value,
        $context->getStartAt()->format('Hhi'),
    );
}])

And I have this error:

Uncaught PHP Exception Doctrine ORM Query QueryException: "[Syntax Error] line 0, col 34: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression, got ‘"’ "

I do not see where the problem is.

Thanks for your help.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *