4

Is there any solution in activeadmin for option where user can hide/unhide column?

2
  • 1
    Hide it from what/where? Commented Oct 24, 2018 at 14:02
  • a column in the indexes? according to the docs you presented, doesn't seem so. Probably you could reload the page with the column you want to hide/unhide - although it is unoptimal in this day and age -, or using AJAX calls to do it without reloading. Or just to create CSS buttons that implement "visibility:hidden" or something. Commented Oct 24, 2018 at 14:22

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.