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

Incomplete idea of filter config with different operators #90

Closed
uap-universe opened this issue Jul 5, 2022 · 3 comments
Closed

Incomplete idea of filter config with different operators #90

uap-universe opened this issue Jul 5, 2022 · 3 comments
Labels
breaking-change Resolving this issue will introduce a breaking change. bug Something isn't working
Milestone

Comments

@uap-universe
Copy link
Collaborator

It seems there was a feature hacked into the filter configuration that allows to combine filters with OR instead of AND.

This feature is, however, very incomplete for the following reasons:

  1. It is not implemented for ServerDataSource
  2. The filter implementation is expensive (it applies each field individually as AND filter with one criterion and then merges the results and tries to get rid of duplicates afterwards instead of properly implementing the OR operator)
  3. It is not possible to combine AND and OR (despite the addFilter signature might suggest that)
  4. The default filter row always reverts the operator back to AND when used

Improving or removing this feature would be both breaking changes. So this issue here is just a reminder that something should be done about this in case a major upgrade is planned eventually.

@uap-universe uap-universe added the breaking-change Resolving this issue will introduce a breaking change. label Jul 5, 2022
@uap-universe uap-universe added this to the v3.0.0 milestone Jul 4, 2023
@uap-universe uap-universe added the bug Something isn't working label Jul 13, 2023
@uap-universe
Copy link
Collaborator Author

The solution is to remove the concept of "operators" and only work with a conjunction of filters for the individual columns.

Secondly, we add a removeFilter() method. In the current implementation, it is only possible to remove a filter by using setFilter() method with an empty set of filters and then re-add all filters that are actually wanted.

The reason why this works is, that "empty string" is ignored by the filter method in the data source. So the lifecycle of a filter is like this:

  1. It starts without a filter for a column
  2. Once the filter in the table header is used, a filter config is added with the query the user entered
  3. When the user removes the filter, the filter is not actually removed, but instead the query is changed to an empty string
  4. Since empty strings are treated as "no filter is set", it looks like the filter was removed, but it actually isn't

@kw-pro
Copy link

kw-pro commented Nov 8, 2023

Hello,
I use the ng2-smart-table before I switch to Angular 16.
Then I switch to angular2-smart-table. Now the OR-Filter Configuration ist not working anymore.
I try to use a ColumnFilterFunction, but I cannot use more than one Column.
Do you have an idea how I can solve this?
Thank you in Advance

@uap-universe
Copy link
Collaborator Author

Yes. You can implement your own data source class by extending LocalDataSource and implement custom external filtering there s.t. the getFilteredAndSorted() method returns the data you want to display.

I recommend to disable all built-in filtering stuff when you implement custom external filters (like e.g. a textfield which allows you to define a query). Otherwise your custom filter might need to merge the built-in filter config with your own filter config and apply that to the data before returning it from getFilteredAndSorted().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Resolving this issue will introduce a breaking change. bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants