Class: ActiveAdmin::Views::TableFor::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/views/components/table_for.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Column) initialize(*args, &block)

Returns a new instance of Column



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/active_admin/views/components/table_for.rb', line 152

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-#{@title.to_s.parameterize('_')}"
  end
  @html_class = html_classes.join(' ')
  @data = args[1] || args[0]
  @data = block if block
  @resource_class = args[2]
end

Instance Attribute Details

- (Object) data

Returns the value of attribute data



150
151
152
# File 'lib/active_admin/views/components/table_for.rb', line 150

def data
  @data
end

- (Object) html_class

Returns the value of attribute html_class



150
151
152
# File 'lib/active_admin/views/components/table_for.rb', line 150

def html_class
  @html_class
end

- (Object) title

Returns the value of attribute title



150
151
152
# File 'lib/active_admin/views/components/table_for.rb', line 150

def title
  @title
end

Instance Method Details

- (Object) pretty_title



207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/active_admin/views/components/table_for.rb', line 207

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

- (Object) sort_key

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'


198
199
200
201
202
203
204
205
# File 'lib/active_admin/views/components/table_for.rb', line 198

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

- (Boolean) sortable?

Returns:

  • (Boolean)


168
169
170
171
172
173
174
175
176
177
178
# File 'lib/active_admin/views/components/table_for.rb', line 168

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