class ActiveAdmin::Views::IndexAsTable


“‘
end
# columns
index row_class: ->elem { ’active’ if elem.active? } do
“‘ruby
of the `index` method.
In order to add special class to table rows pass the proc object as a `:row_class` option
## Custom row class
“`
end
column :secret_data if can? :manage, Post
column :title, sortable: false
index do
“`ruby
For example, if you were using CanCan:
easily do things that show or hide columns based on the current context.
The entire index block is rendered within the context of the view, so you can
## Showing and Hiding Columns
“`
end
column :publisher, sortable: ’publishers.name’
index do
“‘ruby
Then it’s simple to sort by any Publisher attribute from within the index table:
“‘
includes :publisher
“`ruby
`scoped_collection` method:
You can also define associated objects to include outside of the
“`
end
end
super.includes :publisher # prevents N+1 queries to your database
def scoped_collection
controller do
“`ruby
Assuming you’re on the Books index page, and Book has_one Publisher:
can’t sort by associated objects. Though with a few simple changes, you can.
You’re normally able to sort columns alphabetically, but by default you
## Associated Sorting
“‘
end
column :title
index do
end
end
[order_clause.to_sql, ’NULLS FIRST’].join(‘ ’)
else
[order_clause.to_sql, ‘NULLS LAST’].join(‘ ’)
if order_clause.order == ‘desc’
order_by(:title) do |order_clause|
“‘ruby
It is also possible to use database specific expressions and options for sorting by column
## Custom sorting
“`
end
column :keywords, sortable: “meta->’keywords’”
index do
“‘ruby
option to a `column->’key’‘ value:
It’s also possible to sort by PostgreSQL’s hstore column key. You should set ‘sortable`
“`
end
column :title, sortable: false
index do
“`ruby
You can turn off sorting on any column by passing false:
“`
end
end
link_to post.title, admin_post_path(post)
column :title, sortable: :title do |post|
index do
“`ruby
Otherwise, any attribute that the resource collection responds to can be used.
By default, this is the column on the resource’s table that the attribute corresponds to.
You can pass the key specifying the attribute which gets used to sort objects using Active Record.
Active Admin a hint for how to sort the table.
sortable by default. If you are creating a custom column, you may need to give
When a column is generated from an Active Record attribute, the table is
## Sorting
“‘
end
end
a “View”, href: admin_post_path(post)
actions do |post|
column :title
index do
“`ruby
Or append custom action with custom html via arbre:
“`
end
end
item “View”, admin_post_path(post)
actions defaults: false do |post|
column :title
index do
“`ruby
Or forego the default links entirely:
“`
end
end
item “Preview”, admin_preview_post_path(post), class: “preview-link”
actions do |post|
column :title
selectable_column
index do
“`ruby
You can also append custom links to the default links:
“`
end
actions
column :title
selectable_column
index do
“`ruby
To setup links to View, Edit and Delete a resource, use the `actions` method:
## Defining Actions
“`
end
end
link_to post.title, admin_post_path(post)
column “Title” do |post|
selectable_column
index do
“`ruby
The block is called once for each resource, which is passed as an argument to the block.
`column` accepts a block that will be rendered for each of the objects in the collection.
For example, say we wanted a “Title” column that links to the posts admin screen.
Sometimes that just isn’t enough and you need to write some view-specific code.
“‘
end
column “My Custom Title”, :title
selectable_column
index do
“`ruby
If the default title does not work for you, pass it as the first argument:
This can be customized in `config/initializers/active_admin.rb`.
“`
:display_name, :full_name, :name, :username, :login, :title, :email, :to_s
“`ruby
calling the following methods in the following order:
For association columns we make an educated guess on what to display by
“`
end
column :title
selectable_column
index do
“`ruby
column method:
To display an attribute or a method on a resource, simply pass a symbol into the
## Defining Columns
displayed.
show, edit and delete the object. There are many ways to customize what gets
By default, the index page is a table with each of the models content columns and links to
# Index as a Table

def self.index_name

def self.index_name
  "table"
end

def build(page_presenter, collection)

def build(page_presenter, collection)
  add_class "index-as-table"
  table_options = {
    id: "index_table_#{active_admin_config.resource_name.plural}",
    sortable: true,
    i18n: active_admin_config.resource_class,
    paginator: page_presenter[:paginator] != false,
    row_class: page_presenter[:row_class]
  }
  if page_presenter.block
    insert_tag(IndexTableFor, collection, table_options) do |t|
      instance_exec(t, &page_presenter.block)
    end
  else
    render "index_as_table_default", table_options: table_options
  end
end