Question

Dans le fichier dashboards.rb généré par ActiveAdmin 0.3.4, j'ai ajouté trois sections composées sur des tables larges avec plusieurs colonnes . Cependant ActiveAdmin affiche chaque section à côté de l'autre, la création d'une barre de défilement horizontale inutile.

Comment puis-je changer pour une mise en page verticale?

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

Qu'est-ce que je reçois:

tableau de bord aperçu

Je l'ai déjà essayé d'utiliser un div comme conteneur pour chaque table sans chance.

Était-ce utile?

La solution 2

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.

Autres conseils

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

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

You have to use CSS to prevent that

div :class => 'some class name' do

end

style that class

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top