Skip to content
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

Merged
merged 3 commits into from
Apr 29, 2020
Merged

This pull request fixes per-column searches. #120

merged 3 commits into from
Apr 29, 2020

Conversation

vaibhavpandeyvpz
Copy link
Contributor

@vaibhavpandeyvpz vaibhavpandeyvpz commented Jan 2, 2020

Though this fixes column searches for me, it's still to be reviewed by the maintainer if it affects any other adapter as well.

This was referenced Jan 2, 2020
@curry684 curry684 requested a review from shades684 January 2, 2020 13:31
@curry684
Copy link
Member

curry684 commented Jan 2, 2020

@shades684 yours to check 😉

if (!$filter->isValidValue($search)) {
continue;
}
}
$search = $queryBuilder->expr()->literal($search);

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.

Copy link
Contributor

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.

Copy link

@JohnstonCode JohnstonCode Apr 28, 2020

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))) {

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.

@curry684
Copy link
Member

@vaibhavpandeyvpz can you look at the open conversations?
@shades684 can you review it?

@shades684
Copy link
Contributor

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.

@curry684 curry684 merged commit 4cf2e8d into omines:master Apr 29, 2020
@curry684
Copy link
Member

Ok :)

@jkabat
Copy link
Contributor

jkabat commented Apr 29, 2020

I agree with @shades684 - possibility to have column filter with callback option would solve advanced requirements such as date range search and so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants