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.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(*args, &block) ⇒ Column
constructor
A new instance of Column.
-
#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.
133 134 135 136 137 138 |
# File 'lib/active_admin/views/components/table_for.rb', line 133 def initialize(*args, &block) @options = .merge(args.last.is_a?(::Hash) ? args.pop : {}) @title = pretty_title args[0] @data = args[1] || args[0] @data = block if block end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
131 132 133 |
# File 'lib/active_admin/views/components/table_for.rb', line 131 def data @data end |
#title ⇒ Object
Returns the value of attribute title.
131 132 133 |
# File 'lib/active_admin/views/components/table_for.rb', line 131 def title @title end |
Instance Method Details
#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'
166 167 168 169 170 171 172 |
# File 'lib/active_admin/views/components/table_for.rb', line 166 def sort_key if @options[:sortable] == true || @options[:sortable] == false @data.to_s else @options[:sortable].to_s end end |
#sortable? ⇒ Boolean
140 141 142 143 144 145 146 |
# File 'lib/active_admin/views/components/table_for.rb', line 140 def sortable? if @data.is_a?(Proc) [String, Symbol].include?(@options[:sortable].class) else @options[:sortable] end end |