omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
262 stars 113 forks source link

Add DataTable Events #76

Closed MaximePinot closed 5 years ago

MaximePinot commented 5 years ago

Hi,

It can be useful to be able to modify the Query before the iteration starts. I personally need to do this so I can configure the Doctrine cache.

Here's how it works:

$table->createAdapter(ORMAdapter::class, [
    'entity' => Employee::class,
    'query' => function (QueryBuilder $builder) {
        $builder
            ->select('e')
            ->addSelect('c')
            ->from(Employee::class, 'e')
            ->leftJoin('e.company', 'c')
        ;
    },
]);

$table->addEventListener(ORMAdapterEvents::PRE_QUERY, function(ORMAdapterQueryEvent $event) {
    $event->getQuery()->useResultCache(true)->useQueryCache(true);
});
curry684 commented 5 years ago

The core change we just requested is about keeping 1 central reference to the event dispatcher. Passing it around to the adapters may cause issues in the future.

MaximePinot commented 5 years ago

Thank you for your feedback @curry684! Your requested changes are resolved in 04580e7.

curry684 commented 5 years ago

Thank you @MaximePinot!