Class: ActiveAdmin::Views::IndexAsGrid
- Defined in:
- lib/active_admin/views/index_as_grid.rb
Overview
Index as a Grid
Sometimes you want to display the index screen for a set of resources as a grid (possibly a grid of thumbnail images). To do so, use the :grid option for the index block.
index :as => :grid do |product|
link_to(image_tag(product.image_path), admin_products_path(product))
end
The block is rendered within a cell in the grid once for each resource in the collection. The resource is passed into the block for you to use in the view.
You can customize the number of colums that are rendered using the columns option:
index :as => :grid, :columns => 5 do |product|
link_to(image_tag(product.image_path), admin_products_path(product))
end
Class Method Summary collapse
Instance Method Summary collapse
- #build(page_presenter, collection) ⇒ Object
- #build_empty_cell ⇒ Object protected
- #build_item(item) ⇒ Object protected
- #build_row(group) ⇒ Object protected
- #build_table ⇒ Object protected
- #default_number_of_columns ⇒ Object protected
- #number_of_columns ⇒ Object
Class Method Details
.index_name ⇒ Object
37 38 39 |
# File 'lib/active_admin/views/index_as_grid.rb', line 37 def self.index_name "grid" end |
Instance Method Details
#build(page_presenter, collection) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/active_admin/views/index_as_grid.rb', line 26 def build(page_presenter, collection) @page_presenter = page_presenter @collection = collection add_class "index" build_table end |
#build_empty_cell ⇒ Object (protected)
66 67 68 |
# File 'lib/active_admin/views/index_as_grid.rb', line 66 def build_empty_cell td ' '.html_safe end |
#build_item(item) ⇒ Object (protected)
60 61 62 63 64 |
# File 'lib/active_admin/views/index_as_grid.rb', line 60 def build_item(item) td :for => item do instance_exec(item, &@page_presenter.block) end end |
#build_row(group) ⇒ Object (protected)
52 53 54 55 56 57 58 |
# File 'lib/active_admin/views/index_as_grid.rb', line 52 def build_row(group) tr do group.each do |item| item ? build_item(item) : build_empty_cell end end end |
#build_table ⇒ Object (protected)
43 44 45 46 47 48 49 50 |
# File 'lib/active_admin/views/index_as_grid.rb', line 43 def build_table resource_selection_toggle_panel if active_admin_config.batch_actions.any? table :class => "index_grid" do collection.in_groups_of(number_of_columns).each do |group| build_row(group) end end end |
#default_number_of_columns ⇒ Object (protected)
70 71 72 |
# File 'lib/active_admin/views/index_as_grid.rb', line 70 def default_number_of_columns 3 end |
#number_of_columns ⇒ Object
33 34 35 |
# File 'lib/active_admin/views/index_as_grid.rb', line 33 def number_of_columns @page_presenter[:columns] || default_number_of_columns end |