Class: TableSettings::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/table_settings/table_column.rb

Direct Known Subclasses

CustomColumn, StandardColumn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_settings, index) ⇒ Column

Returns a new instance of Column.



8
9
10
11
12
# File 'lib/table_settings/table_column.rb', line 8

def initialize(table_settings, index)
  @table_settings = table_settings
  @column_hash = {}
  @index = index
end

Instance Attribute Details

#indexObject

Returns the value of attribute index.



6
7
8
# File 'lib/table_settings/table_column.rb', line 6

def index
  @index
end

Instance Method Details

#column_hashObject



14
15
16
# File 'lib/table_settings/table_column.rb', line 14

def column_hash
  @column_hash
end

#css_class(class_name) ⇒ Object



18
19
20
21
22
# File 'lib/table_settings/table_column.rb', line 18

def css_class(class_name)
  @column_hash[:class] = class_name

  self
end

#css_header_class(class_name) ⇒ Object



23
24
25
26
27
# File 'lib/table_settings/table_column.rb', line 23

def css_header_class(class_name)
  @column_hash[:header_class] = class_name

  self
end

#editable(bool = true) ⇒ Object

For editable table, defines wchich column should be editable



108
109
110
111
# File 'lib/table_settings/table_column.rb', line 108

def editable(bool = true)
  @column_hash[:editable] = bool
  self
end

#filter_data(array) ⇒ Object



47
48
49
50
51
# File 'lib/table_settings/table_column.rb', line 47

def filter_data(array)
  @column_hash[:filter_data] = array

  self
end

#filter_type(filter_type) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/table_settings/table_column.rb', line 29

def filter_type(filter_type)
  if filter_type == :none
    @column_hash.delete(:filter)
  else
    @column_hash[:filter] = filter_type
  end

  self
end

#format_method(method_name) ⇒ Object



59
60
61
62
63
# File 'lib/table_settings/table_column.rb', line 59

def format_method(method_name)
  @column_hash[:format_method] = method_name

  self
end

#global_format_method(method_name) ⇒ Object

Sets global format method used for values



66
67
68
69
70
# File 'lib/table_settings/table_column.rb', line 66

def global_format_method(method_name)
  @column_hash[:global_format_method] = method_name

  self
end

#max_text_length(length) ⇒ Object



53
54
55
56
57
# File 'lib/table_settings/table_column.rb', line 53

def max_text_length(length)
  @column_hash[:max_text_length] = length

  self
end

#non_breakable(bool = true) ⇒ Object

Defines column with non-breakable content (for example column with more buttons)

Parameters:

  • bool (Boolean) (defaults to: true)


102
103
104
105
# File 'lib/table_settings/table_column.rb', line 102

def non_breakable(bool = true)
  @column_hash[:non_breakable] = bool
  self
end

#sql_expression(expression) ⇒ Object

Defines select expression for column (ie. select count(id) as counter)



42
43
44
45
# File 'lib/table_settings/table_column.rb', line 42

def sql_expression(expression)
  @column_hash[:sql_expression] = expression
  self
end

#summarize_all(enabled = true, label = nil) ⇒ Object

Sets if column has summarization cell per table Standard column will be computed Custom column have to set TableSettings::Buttons.summarize_all_value in callback method

Parameters:

  • enabled (Boolean) (defaults to: true)
    • has/has not this cell

  • label (String|nil) (defaults to: nil)

    in this cell (for example “Summary”)



92
93
94
95
96
# File 'lib/table_settings/table_column.rb', line 92

def summarize_all(enabled = true, label = nil)
  @column_hash[:summarize_all] = true
  @column_hash[:summarize_all_label] = label unless label.nil?
  self
end

#summarize_page(enabled = true, label = nil) ⇒ Object

Sets if column has summarization cell per page Standard column will be computed Custom column have to set TableSettings::Buttons.summarize_page_value in callback method

Parameters:

  • enabled (Boolean) (defaults to: true)
    • has/has not this cell

  • label (String|nil) (defaults to: nil)

    in this cell (for example “Summary”)



79
80
81
82
83
# File 'lib/table_settings/table_column.rb', line 79

def summarize_page(enabled = true, label = nil)
  @column_hash[:summarize_page] = true
  @column_hash[:summarize_page_label] = label unless label.nil?
  self
end