Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set dropdown search type default for Active Admin gem sidebar filters

I am using the ActiveAdmin rails gem and have several filters configured for one of my models. For one of the string filters I would like to set the search type dropdown ("Contains", "Equals", "Starts with", "Ends with") to default to "Equals" instead of "Contains".

Also, similarly I would like to set one of my numeric filters to default to "Greater Than" instead of "Equals".

Here's the relevant configuration...

filter :message
filter :likes_count, as: :numeric
like image 767
user3032911 Avatar asked Feb 21 '14 02:02

user3032911


1 Answers

This would solve the second one and you should be able to use the same pattern to fix the first.

filter :likes_count, as: :numeric, filters: ['gt', 'lt', 'eq']

Where gt is greater than, lt less than, eq is equal. You can rearrange or remove any you don't need. You will need to make sure you have a translation setup in your en.yml file

So in your config/locales/en.yml

en:
  active_admin:
    filters:
      predicates:
        predicates:
          contains: "Contains"
          equals: "Equals"
          eq: "Equals"
          starts_with: "Starts with"
          ends_with: "Ends with"
          greater_than: "Greater than"
          gt: "Greater than"
          less_than: "Less than"
          lt: "Less than"
like image 181
emcanes Avatar answered Sep 27 '22 20:09

emcanes