Class: Trestle::Table::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/table/column.rb

Defined Under Namespace

Classes: Renderer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, field, options = {}, &block) ⇒ Column

Returns a new instance of Column.



6
7
8
9
# File 'lib/trestle/table/column.rb', line 6

def initialize(table, field, options={}, &block)
  @table, @field, @options = table, field, options
  @block = block if block_given?
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def block
  @block
end

#fieldObject (readonly)

Returns the value of attribute field.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def field
  @field
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def options
  @options
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/trestle/table/column.rb', line 4

def table
  @table
end

Instance Method Details

#headerObject



31
32
33
34
35
36
37
38
39
# File 'lib/trestle/table/column.rb', line 31

def header
  if options[:header]
    options[:header]
  elsif table.admin
    table.admin.t("table.headers.#{field}", default: table.admin.human_attribute_name(field))
  else
    I18n.t("admin.table.headers.#{field}", default: field.to_s.humanize.titleize)
  end
end

#renderer(template) ⇒ Object



11
12
13
# File 'lib/trestle/table/column.rb', line 11

def renderer(template)
  Renderer.new(self, template)
end

#sort_fieldObject



19
20
21
22
23
24
25
# File 'lib/trestle/table/column.rb', line 19

def sort_field
  if options[:sort].is_a?(Hash)
    options[:sort][:field] || field
  else
    options[:sort] || field
  end
end

#sort_optionsObject



27
28
29
# File 'lib/trestle/table/column.rb', line 27

def sort_options
  options[:sort].is_a?(Hash) ? options[:sort] : {}
end

#sortable?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/trestle/table/column.rb', line 15

def sortable?
  table.sortable? && options[:sort] != false && (!@block || options.has_key?(:sort))
end