Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to layout the dashboard sections vertically with ActiveAdmin?

In the dashboards.rb file generated by ActiveAdmin 0.3.4, I added three sections consisting on wide tables with several columns. However ActiveAdmin displays each section next to the other, creating an unnecessary horizontal scrollbar.

How can I change this to a vertical layout?

dashboards.rb:

ActiveAdmin::Dashboards.build do
  section "Inactive users" do
    table do
      ...
    end
  end

  section "Deleted posts" do
    table do
      ...
    end
  end

  section "Latest comments" do
    table do
      ...
    end
  end
end

What I get:

dashboard preview

I already tried using a div as the container for each table with no luck.

like image 207
alf Avatar asked Dec 01 '22 23:12

alf


2 Answers

This answer for active_admin >= 0.5.1

Dashboard is structured in columns and panels Columns are... well, columns, which define the horizontal layout. Panels are like sections that stack verticaly.

A 2 column, 3 sections en each column, would be defined by:

columns do
  column do
    panel "top on column 1"
      # some code
    end
    panel "second on column 1"
      # some code
    end
    panel "last on column 1"
      # some code
    end
  end
  column do
    panel "top on column 2"
      # some code
    end
    panel "second on column 2"
      # some code
    end
    panel "last on column 2"
      # some code
    end
  end
end
like image 139
Carlos Troncoso Avatar answered Dec 28 '22 08:12

Carlos Troncoso


I finally fixed this with some CSS, in a new stylesheet:

active_admin_ex.css:

table.dashboard > tbody > tr > td {
  display:block;
}

Then, in config/initializers/active_admin.rb, I added:

config.register_stylesheet 'active_admin_ex.css'

And this fixed the display problem.

like image 30
alf Avatar answered Dec 28 '22 09:12

alf