Is there any solution in activeadmin for option where user can hide/unhide column?
Out of the box, no. You would need to define a data structure to hold the user's preferences then define your index something like:
index do
  column :title unless current_user.hide_column?(:title)
  ...
end
The simplest way to hold the preferences would be a UserColumnPreference resource which itself could be managed through ActiveAdmin. More sophisticated solutions might involve using AJAX, subclassing ActiveAdmin::IndexAsTable, etc.
If you don't need to persist the preference then a simple JavaScript to manipulate the HTML table on the page will do, eg. Hiding columns in table JavaScript This is unrelated to ActiveAdmin.
I found a neat solution for this. Saving it as a session variable.
Complete solution:
This creates a button on the index page that says show or hide images depending on the state:
  action_item :toggle_image_view, only: :index do
    link_to (session['hide_images'] || false) ? t('views.admin.show_images') : t('views.admin.hide_images') , toggle_image_view_admin_person_poses_path
  end
This toggles the session key and shows the index page again:
  collection_action :toggle_image_view, method: :get do
    session['hide_images'] = !(session['hide_images'] || false)
    redirect_to collection_path
  end
Here you see the column that will get displayed or not depending on the session variable. Default is set to display them.
  index do
    selectable_column
    id_column
    column :camera
    unless (session['hide_images'] || false)
      column :image
    end
    actions
  end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With