简体   繁体   中英

Cascading custom filter on ActiveAdmin

I am trying to create a cascading filter on ActiveAdmin, and I am not quite sure how to go about it.

I have three models that have successive belongs_to/has_many relationships, eg A has many B's, and B has many C's.

I can create three filters like the following, and they work, but what I want to do is to limit B collection based on choice in A.

  filter :b_a_name, :as => :select, :collection => A.map(&:name)
  filter :b_name, :as => :select, :collection => B.map(&:name)
  filter :year

Is there anyway to accomplish this on ActiveAdmin?

Thank for help in advance!

You can accomplish something like this using javascript, ie

  • Listen to the change event on b_a_name
  • Make an ajax request to an endpoint with the selection in b_a_name with
  • Return an JSON array of the corresponding options for b_name in your success callback
  • Replace the select options for b_name with options in array

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM