-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This pull request fixes per-column searches. #120
Conversation
@shades684 yours to check 😉 |
if (!$filter->isValidValue($search)) { | ||
continue; | ||
} | ||
} | ||
$search = $queryBuilder->expr()->literal($search); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to build the search variable using the following:
$search = $queryBuilder->expr()->literal($column->getRightExpr($search));
Otherwise the % characters aren't added to the search string and partial matches won't happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also sometimes is necessary to use much more complicated comparisons in order to implement filtering with date range and such. CriteriaFilter with callback option would solve case like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping $column->getRightExpr($search)
in literal
will stop IN
operator from working
@@ -111,7 +111,7 @@ private function handleSearch(ParameterBag $parameters) | |||
$column = $this->dataTable->getColumn((int) $key); | |||
$value = $this->isInitial ? $search : $search['search']['value']; | |||
|
|||
if ($column->isSearchable() && '' !== trim($value) && null !== $column->getFilter() && $column->getFilter()->isValidValue($value)) { | |||
if ($column->isSearchable() && ('' !== trim($value))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is essential to implement other adapters. I created an adapter for DBAL but I need this change to do PR.
@vaibhavpandeyvpz can you look at the open conversations? |
I'm fine with the solution as is. In the long run we should have a different and more generic solution. I'd rather have some sort of callback per column if it's searchable so we can have the user extend the query. What I'm missing in the current solution is: What happens if we have a datefield and we search for the string 20. Is 1-1-2000 valid or maybe 1-1-1920. The solution that's defined here isn't generic (it's opinionated), but it solves/fixes a problem. |
Ok :) |
I agree with @shades684 - possibility to have column filter with callback option would solve advanced requirements such as date range search and so on. |
Though this fixes column searches for me, it's still to be reviewed by the maintainer if it affects any other adapter as well.