Reputation: 18550
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:
I already tried using a div as the container for each table with no luck.
Upvotes: 4
Views: 9012
Reputation: 13
columns do
column do
panel "Recent Created Restaurant" do
table_for Restaurant.order('id desc').limit(5).each do |restaurant|
column (:id) {|restaurant| link_to(restaurant.id, admin_restaurant_path(restaurant)) }
column :name
column :phone
column :updated_at
end # table
end # panel
end # column
column do
panel "Recent Created Menu" do
table_for Menu.order('id desc').limit(5).each do |menu|
column (:id) {|menu| link_to(menu.id, admin_menu_path(menu)) }
column :name
column "Restaurant Name" do |menu|
menu.restaurant.name
end
column :updated_at
end # table
end # panel
end # column
column do
panel "Recent Created Order" do
table_for Order.order('id desc').limit(5).each do |order|
column (:id) {|order| link_to(order.id, admin_order_path(order)) }
column :table
column :status
column "Item Name" do |order|
order.item_orders.id
end
column :updated_at
end # table
end # panel
end # column
end # columns
Upvotes: 0
Reputation: 683
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
Upvotes: 12
Reputation: 4761
more flexible, you can override the render_sections of the Dashboard class to use colspan:
module ActiveAdmin
module Views
module Pages
class Dashboard < Base
protected
def render_sections(sections)
cloned_sections = sections.clone
table :class => "dashboard" do
while !cloned_sections.empty?
current_cols_number = 0
tr do
while current_cols_number < 12 && !cloned_sections.empty?
s = cloned_sections.shift
colspan = s.options[:colspan].nil? ? 4 : s.options[:colspan]
td colspan: colspan do
render_section(s)
end
current_cols_number += colspan
end
end
end
end
end
end
end
end
end
you can add this code at the beginning of you app/admin/dashboard.rb
file and then add the :colspan
option when declaring a section:
section "All time summary" , colspan: 6 , priority: 2 do
div do
render 'all_time_summary'
end
end
Upvotes: 2
Reputation: 654
You have to use CSS to prevent that
div :class => 'some class name' do
end
style that class
Upvotes: 0
Reputation: 18550
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.
Upvotes: 4