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

#initialize(*args, &block) ⇒ Column

Returns a new instance of Column.



150
151
152
153
154
155
156
157
158
# File 'lib/active_admin/views/components/table_for.rb', line 150

def initialize(*args, &block)
  @options = args.extract_options!
  @title = args[0]
  @title_id = @title.to_s.parameterize(separator: "_") if @title.present? && !title.is_a?(Arbre::Element)
  @html_class = @options.delete(:class)
  @data = args[1] || args[0]
  @data = block if block
  @resource_class = args[2]
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



148
149
150
# File 'lib/active_admin/views/components/table_for.rb', line 148

def data
  @data
end

#html_classObject

Returns the value of attribute html_class.



148
149
150
# File 'lib/active_admin/views/components/table_for.rb', line 148

def html_class
  @html_class
end

#titleObject

Returns the value of attribute title.



148
149
150
# File 'lib/active_admin/views/components/table_for.rb', line 148

def title
  @title
end

#title_idObject

Returns the value of attribute title_id.



148
149
150
# File 'lib/active_admin/views/components/table_for.rb', line 148

def title_id
  @title_id
end

Instance Method Details

#pretty_titleObject



190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/active_admin/views/components/table_for.rb', line 190

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_keyObject

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'


181
182
183
184
185
186
187
188
# File 'lib/active_admin/views/components/table_for.rb', line 181

def sort_key
  # If boolean or nil, use the default sort key.
  if @options[:sortable].nil? || @options[:sortable] == true || @options[:sortable] == false
    sort_column_name
  else
    @options[:sortable].to_s
  end
end

#sortable?Boolean

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
# File 'lib/active_admin/views/components/table_for.rb', line 160

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