@@ -6,123 +6,14 @@ you to build a compelling interface into your data for the admin staff.
66
77Built in, Active Admin has the following index renderers:
88
9- * * Table* : A table drawn with each row being a resource
10- * * Grid* : A set of rows and columns each cell being a resource
11- * * Blocks* : A set of rows (not tabular) each row being a resource
12- * * Blog* : A title and body content, similar to a blog index
9+ * * Table* : A table drawn with each row being a resource ( [ View Table Docs ] ( 3-index-pages/index-as-table.md ) )
10+ * * Grid* : A set of rows and columns each cell being a resource ( [ View Grid Docs ] ( 3-index-pages/index-as-grid.md ) )
11+ * * Blocks* : A set of rows (not tabular) each row being a resource ( [ View Blocks Docs ] ( 3-index-pages/index-as-blocks.md ) )
12+ * * Blog* : A title and body content, similar to a blog index ( [ View Blog Docs ] ( 3-index-pages/index-as-blog.md ) )
1313
1414All index pages also support scopes, filters, pagination, action items, and
1515sidebar sections.
1616
17- ## Index as a Table
18-
19- By default, the index page is a table with each of the models content columns and links to
20- show, edit and delete the object. There are many ways to customize what gets
21- displayed.
22-
23- ### Defining Columns
24-
25- To display an attribute or a method on a resource, simply pass a symbol into the
26- column method:
27-
28- index do
29- column :title
30- end
31-
32- If the default title does not work for you, pass it as the first argument:
33-
34- index do
35- column "My Custom Title", :title
36- end
37-
38- Sometimes calling methods just isn't enough and you need to write some view
39- specific code. For example, say we wanted a colum called Title which holds a
40- link to the posts admin screen.
41-
42- The column method accepts a block as an argument which will then be rendered
43- within the context of the view for each of the objects in the collection.
44-
45- index do
46- column "Title" do |post|
47- link_to post.title, admin_post_path(post)
48- end
49- end
50-
51- The block gets called once for each resource in the collection. The resource gets passed into
52- the block as an argument.
53-
54-
55- ### Sorting
56-
57- When a column is generated from an Active Record attribute, the table is
58- sortable by default. If you are creating a custom column, you may need to give
59- Active Admin a hint for how to sort the table.
60-
61- If a column is defined using a block, you must pass the key to turn on sorting. The key
62- is the attribute which gets used to sort objects using Active Record.
63-
64- index do
65- column "Title", :sortable => :title do |post|
66- link_to post.title, admin_post_path(post)
67- end
68- end
69-
70- You can turn off sorting on any column by passing false:
71-
72- index do
73- column :title, :sortable => false
74- end
75-
76- ### Showing and Hiding Columns
77-
78- The entire index block is rendered within the context of the view, so you can
79- easily do things that show or hide columns based on the current context.
80-
81- For example, if you were using CanCan:
82-
83- index do
84- column :title, :sortable => false
85- if can? :manage, Post
86- column :some_secret_data
87- end
88- end
89-
90- ## Index as a Grid
91-
92- Sometimes you want to display the index screen for a set of resources as a grid
93- (possibly a grid of thumbnail images). To do so, use the : grid option for the
94- index block.
95-
96- index :as => :grid do |product|
97- link_to(image_tag(product.image_path), admin_products_path(product))
98- end
99-
100- The block is rendered within a cell in the grid once for each resource in the
101- collection. The resource is passed into the block for you to use in the view.
102-
103- You can customize the number of colums that are rendered using the columns
104- option:
105-
106- index :as => :grid, :columns => 5 do |product|
107- link_to(image_tag(product.image_path), admin_products_path(product))
108- end
109-
110-
111- ## Index as a Block
112-
113- If you want to fully customize the display of your resources on the index
114- screen, Index as a Block allows you to render a block of content for each
115- resource.
116-
117- index :as => :block do |product|
118- div :for => product do
119- h2 auto_link(product.title)
120- div do
121- simple_format product.description
122- end
123- end
124- end
125-
12617## Index Filters
12718
12819By default the index screen includes a "Filters" sidebar on the right hand side
0 commit comments