The Wayback Machine - https://web.archive.org/web/20200907182635/https://github.com/activeadmin/activeadmin/issues/3662
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

Add 'not' options to filter #3662

Open
jostster opened this issue Nov 28, 2014 · 6 comments
Open

Add 'not' options to filter #3662

jostster opened this issue Nov 28, 2014 · 6 comments

Comments

@jostster
Copy link

@jostster jostster commented Nov 28, 2014

There should be 'does not contain' or 'does not have' option in the filters. I have a :through relationship and want to be able to filter results based on entries that do not have a specific relationship. This should be togglable so that the admin can either use it to find records that DOES contain the relation or DOES NOT contain the relation. Also being able to add this to strings would be needed so admins can find users or fields that were left empty. A good filter system that has these options that can be used used to see what I am talking about is keystonejs.

@att14
Copy link

@att14 att14 commented Nov 17, 2015

+1

@Fivell
Copy link
Member

@Fivell Fivell commented Jun 25, 2017

@jostster ,
for relationships you can use

ActiveAdmin.register Order do
  filter :user_id_not_eq, label: 'Except User', as: :select, collection: ->{ User.all }
end
@Fivell
Copy link
Member

@Fivell Fivell commented Jun 25, 2017

string search is still possible

ActiveAdmin.register User do
   filter :username, filters: [:not_start,  :not_end, :not_cont]
end

one issue is there is no aliases to use it like not_starts_with, not_ends_with ... and not translations for this.
I think providing aliases and documenting it to close the issue.
@varyonic , what do you think ?

@ryanflach
Copy link

@ryanflach ryanflach commented Jan 15, 2018

Using version 1.0.0.pre of ActiveAdmin, I was able to implement 'Does Not Contain' to a string filter with a few small workarounds, guided mostly by @Fivell's last comment.

ActiveAdmin.register User do
  filter :username, as: :string, filters: [:contains, :equals, :starts_with, :ends_with, :not_contains]
end

Note that in order to include the default options in the drop-down, they needed to be included, and :not_cont needed to be changed to :not_contains.

In my en.yml translations file, I needed to add a translation for :not_contains:

en:
  active_admin:
    filters:
      predicates:
        not_contains: "Does Not Contain"

With these in place, filtering by 'Does Not Contain' works as expected.

Edit: This does not work as expected. It will simply return no results.

@ghilead
Copy link

@ghilead ghilead commented Apr 3, 2019

@ryanflach I managed to get this working by using :not_cont and adding the translation for not_cont

@yagudaev
Copy link
Contributor

@yagudaev yagudaev commented May 9, 2019

@ghilead and @ryanflach thanks guys it works like a charm. It would be nice to add these across the board for any string.

This should really be a PR, such a great feature.

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

Successfully merging a pull request may close this issue.

None yet
7 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.