datatables-bundle icon indicating copy to clipboard operation
datatables-bundle copied to clipboard

Ability to use IN in column level searches

Open JohnstonCode opened this issue 5 years ago • 4 comments

Is there a way to use IN in column level searches? I don't think this is currently possible due to https://github.com/omines/datatables-bundle/blob/master/src/Adapter/Doctrine/ORM/SearchCriteriaProvider.php#L49 which will turn the right operator into 1,2 if you are using ids to narrow the search instead of (1,2)

My proposed solution was https://github.com/omines/datatables-bundle/pull/150 which had the filter column as callable and the callable is passed QueryBuilder $queryBuilder, $field, $search and then the filter can be added like so

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

    $queryBuilder
    	->andWhere($queryBuilder->expr()->in($field, ':users'))
		->setParameter('users', $users);
}

What other options are there to add flexible column level search?

JohnstonCode avatar Jun 16 '20 12:06 JohnstonCode

You should probably extend SearchCriteriaProvider and use your own type of filter (eg: CriteriaFilter/CallableFilter). Maybe there is other way I was not able to figure out yet.

jkabat avatar Jun 16 '20 12:06 jkabat

I see what you mean, that is indeed an unfortunate exception to the general case.

@shades684 what's your take on this?

curry684 avatar Jun 16 '20 14:06 curry684

I still think that a column should know absolutely nothing about processing the filter value it's been given. The query is part of Orm in this case and filtering is part of a search criteria provider.

For now @jkabat's solution is the right one for now.

I think @curry684 still has the open issue #15 which is half of the solution. The other part is being able to extend your queries from the ormadapter with callables

shades684 avatar Jun 16 '20 17:06 shades684

Mmm yes correct, #15 is partially at the core of this. I indeed don't see another 'quick route' to a solution here, it's an interesting yet rare case it would seem (took people long enough to run into this).

curry684 avatar Jun 16 '20 19:06 curry684

Stale issue message

github-actions[bot] avatar Nov 23 '22 22:11 github-actions[bot]