class ActiveAdmin::Views::TableFor::Column
def initialize(*args, &block)
def initialize(*args, &block) @options = args.extract_options! @title = args[0] @html_class = @options.delete(:class) || @title.to_s.downcase.underscore.gsub(/ +/,'_') @data = args[1] || args[0] @data = block if block @resource_class = args[2] end
def pretty_title
def pretty_title if @title.is_a?(Symbol) default_title = @title.to_s.titleize if @options[:i18n] && @options[:i18n].respond_to?(:human_attribute_name) @title = @options[:i18n].human_attribute_name(@title, :default => default_title) else default_title end else @title end end
def sort_key
# => Sort key will be 'login'
column('Username', :sortable => 'login'){ @user.pretty_name }
sort the column on:
will not be sortable unless you pass a string to sortable to
If you pass a block to be rendered for this column, the column
column :username, :sortable => 'other_column_to_sort_on'
to the sortable option:
You can set the sort key by passing a string or symbol
# => Sort key will be set to 'username'
column :username
Defaults to the column's method if its a symbol
Returns the key to be used for sorting this column
def sort_key # If boolean or nil, use the default sort key. if @options[:sortable] == true || @options[:sortable] == false || @options[:sortable].nil? @data.to_s else @options[:sortable].to_s end end
def sortable?
def sortable? if @data.is_a?(Proc) [String, Symbol].include?(@options[:sortable].class) elsif @options.has_key?(:sortable) @options[:sortable] elsif @data.respond_to?(:to_sym) && @resource_class !@resource_class.reflect_on_association(@data.to_sym) else true end end