omines / datatables-bundle

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

Added the ability for column filter to be callable #150

Closed JohnstonCode closed 4 years ago

JohnstonCode commented 4 years ago

This PR adds the ability make filter callable.

'filter' => function (QueryBuilder $queryBuilder, $field, $search) {
    $users = explode(',', str_replace(' ', '', $search));

    $queryBuilder
        ->andWhere($queryBuilder->expr()->in($field, ':users'))
        ->setParameter('users', $users);
}
curry684 commented 4 years ago

Thanks, and my apologies for not noticing it before, but I'm closing this PR. I see what you want to achieve but it's not the right way to do so - you should just implement your own filter based on AbstractFilter. As PHP now has anonymous classes this is just as convenient as adding a callable option here which would just complicate our core code.