class ActiveAdmin::Views::TableFor::Column

Attributes

data[RW]
html_class[RW]
title[RW]

Public Class Methods

new(*args, &block) click to toggle source
# File lib/active_admin/views/components/table_for.rb, line 142
def initialize(*args, &block) 
  @options = args.extract_options!

  @title = args[0]
  html_classes = [:col]
  if @options.has_key?(:class)
    html_classes << @options.delete(:class)
  elsif @title.present?
    html_classes << "col-#{ActiveAdmin::Dependency.rails.parameterize(@title.to_s)}"
  end
  @html_class = html_classes.join(' ')
  @data = args[1] || args[0]
  @data = block if block
  @resource_class = args[2]
end

Public Instance Methods

pretty_title() click to toggle source
# File lib/active_admin/views/components/table_for.rb, line 197
def pretty_title
  if @title.is_a? Symbol
    default = @title.to_s.titleize
    if @options[:i18n].respond_to? :human_attribute_name
      @title = @options[:i18n].human_attribute_name @title, default: default
    else
      default
    end
  else
    @title
  end
end
sort_key() click to toggle source

Returns the key to be used for sorting this column

Defaults to the column’s method if its a symbol

column :username
# => Sort key will be set to 'username'

You can set the sort key by passing a string or symbol to the sortable option:

column :username, sortable: 'other_column_to_sort_on'

If you pass a block to be rendered for this column, the column will not be sortable unless you pass a string to sortable to sort the column on:

column('Username', sortable: 'login'){ @user.pretty_name }
# => Sort key will be 'login'
# File lib/active_admin/views/components/table_for.rb, line 186
def sort_key
  # If boolean or nil, use the default sort key.
  if @options[:sortable] == true || @options[:sortable] == false
    @data.to_s
  elsif @options[:sortable].nil?
    sort_column_name
  else
    @options[:sortable].to_s
  end
end
sortable?() click to toggle source
# File lib/active_admin/views/components/table_for.rb, line 158
def sortable?
  if @options.has_key?(:sortable)
    !!@options[:sortable]
  elsif @resource_class
    @resource_class.column_names.include?(sort_column_name)
  else
    @title.present?
  end
end

Private Instance Methods

sort_column_name() click to toggle source
# File lib/active_admin/views/components/table_for.rb, line 212
def sort_column_name
  @data.is_a?(Symbol) ? @data.to_s : @title.to_s
end