Class: ActiveAdmin::Views::TableFor::Column
- Inherits:
-
Object
- Object
- ActiveAdmin::Views::TableFor::Column
- Defined in:
- lib/active_admin/views/components/table_for.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#html_class ⇒ Object
Returns the value of attribute html_class.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Column
constructor
A new instance of Column.
- #pretty_title ⇒ Object
-
#sort_key ⇒ Object
Returns the key to be used for sorting this column.
- #sortable? ⇒ Boolean
Constructor Details
#initialize(*args, &block) ⇒ Column
Returns a new instance of Column.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/active_admin/views/components/table_for.rb', line 142 def initialize(*args, &block) @options = args. @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 |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
140 141 142 |
# File 'lib/active_admin/views/components/table_for.rb', line 140 def data @data end |
#html_class ⇒ Object
Returns the value of attribute html_class.
140 141 142 |
# File 'lib/active_admin/views/components/table_for.rb', line 140 def html_class @html_class end |
#title ⇒ Object
Returns the value of attribute title.
140 141 142 |
# File 'lib/active_admin/views/components/table_for.rb', line 140 def title @title end |
Instance Method Details
#pretty_title ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 |
# 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 ⇒ Object
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'
186 187 188 189 190 191 192 193 194 195 |
# 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? ⇒ Boolean
158 159 160 161 162 163 164 165 166 |
# 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 |