Skip to content
bbenezech edited this page Dec 26, 2011 · 28 revisions

Section used for the index view.

It inherits its configuration from the base section.

Number of items per page

You can configure the default number of rows rendered per page:

RailsAdmin.config do |config|
  config.default_items_per_page = 50
end

Number of items per page per model

You can also configure it per model:

RailsAdmin.config do |config|
  config.model Team do
    list do
      items_per_page 100
    end
  end
end

Default sorting

By default, rows are sorted by the field id in reverse order

You can change default behavior with use two options: sort_by and sort_reverse

RailsAdmin.config do |config|
  config.model Player do
    list do
      sort_by :name
      sort_reverse false
    end
  end
end

Filters

Default visible filters. Must be a list of fields name.

RailsAdmin.config do |config|
  config.model Team do
    list do
      filters [:name, :manager]
    end
  end
end

Fields sorting

You can make a column non-sortable by setting the sortable option to false (1) You can change the column that the field will actually sort on (2) Belongs_to associations : will be sorted on their label if label is not virtual (:name, :title, etc.) otherwise on the foreign_key (:team_id) you can also specify a column on the targetted table (see example) (3)

RailsAdmin.config do |config|
  config.model Player do
    list do
      field :created_at do # (1)
        sortable false
      end
      field :name do # (2)
       sortable :last_name # imagine there is a :last_name column and that :name is virtual
      end
      field :team do # (3)
        # Will order by players playing with the best teams,
        # rather than the team name (by default),
        # or the team id (dull but default if object_label_method is not a column name)

        sortable :win_percentage

        # if you need to specify the join association name:
        # (See #526 and http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html => table_aliasing)
        sortable {:teams => :win_percentage}
        # or
        sortable "teams.win_percentage"
       end
    end
  end
end

By default, dates and serial ids are reversed when first-sorted ('desc' instead of 'asc' in SQL). If you want to reverse (or cancel it) the default sort order (first column click or the default sort column):

RailsAdmin.config do |config|
  config.model Team do
    list do
      field :id do
        sort_reverse false   # will sort id increasing ('asc') first ones first (default is last ones first)
      end
      field :created_at do
        sort_reverse false   # will sort dates increasing ('asc') first ones first (default is last ones first)
      end
      field :name do
        sort_reverse true    # will sort name decreasing ('dec') z->a (default is a->z)
      end
    end
  end
end

Fields searching

You can make a column non-searchable by setting the searchable option to false (1) You can change the column that the field will actually search on (2) You can specify a list of column that will be searched over (3) Belongs_to associations : will be searched on their foreign_key (:team_id) or on their label if label is not virtual (:name, :title, etc.) you can also specify columns on the targetted table or the source table (see example) (4)

RailsAdmin.config do |config|
  config.model Player do
    list do
      field :created_at do # (1)
        searchable false
      end

      field :name do (2)
        searchable :last_name
      end
      # OR
      field :name do (3)
        searchable [:first_name, :last_name]
      end

      field :team do # (4)
        searchable [:name, :id]
        # eq. to [Team => :name, Team => :id]
        # or even [:name, Player => :team_id] will search on teams.name and players.team_id
        # if you need to specify the join association name:
        # (See #526 and http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html => table_aliasing)
        searchable [{:teams => :name}, {:teams => :id}]
        # or
        searchable ["teams.name", "teams.id"]
      end
    end
  end
end

Searchable definitions will be used for searches and filters. You can independently deactivate querying (search) or filtering for each field with:

field :team do
  searchable [:name, :color]
  queryable true # default
  filterable false
end

More here

Clone this wiki locally