I’m using ActiveAdmin with Ruby on Rails to develop an admin section of a webapp. I’m building an index page for a model that has a lot of attributes. Most of these attributes I’ve enabled filters for, but I can’t show them all on the index table because it becomes too cluttered. Is there a way to dynamically show/hide columns on the table based on what filters are used? Is there a better approach to this problem?
Share
I’ve found a bit of an answer to this problem, but it’s not pretty and definitely not very DRY.
You can actually use
ifstatements inside the ActiveAdmin DSLindexmethod. Also, ActiveAdmin passes filters as aq[]GET parameter. For instance, a string field named “username” would be theq[username_contains]GET parameter. A numeric field named “number_of_posts” could beq[number_of_posts_eq]. Using this we can look at an example where we display number of posts if they’ve been filtered, or the user’s email address, if they haven’t:Of course, there are many different filter types, so the query parameters are all going to be different depending on the type. Even the numeric type has
_eq,_lt, and_gtsuffixes for equals, less-than, and greater-than respectively.