Class: Fancygrid::Column
Instance Attribute Summary collapse
-
#formatable ⇒ Object
If true, the root node has a formatter method for this column.
-
#hidden ⇒ Object
If true, this column is not rendered.
-
#position ⇒ Object
The column position in table.
-
#search_operator ⇒ Object
The current search operator for this column.
-
#search_options ⇒ Object
The possible search options for this column.
-
#search_value ⇒ Object
The current search value for this column.
-
#searchable ⇒ Object
If true, a search field is then rendered for this column.
-
#selectable ⇒ Object
If true, this column is treated as a database column.
-
#value_proc ⇒ Object
Value resolver proc for this column.
-
#width ⇒ Object
The column width.
Attributes inherited from Node
#children, #name, #parent, #resource_class, #root, #table_name
Instance Method Summary collapse
-
#collect_columns(collection) ⇒ Object
Adds this column to the given collection.
-
#default_human_name ⇒ Object
Gets the default human name for this column.
-
#fetch_value(record) ⇒ Object
Fetches a value from given record.
-
#fetch_value_and_format(record) ⇒ Object
Fetches a value from given record and tries to apply the format method.
-
#formatter_method ⇒ Object
Gets the method name that is send to the root node to format the value of a column cell.
-
#human_name ⇒ Object
Gets the internationalized, human readable name for this column.
-
#i18n_path ⇒ Object
Gets the internationalization lookup path for this column.
-
#identifier ⇒ Object
Gets the column identifier.
-
#initialize(parent, name, options = {}) ⇒ Column
constructor
A new instance of Column.
-
#sort_order ⇒ Object
Gets the current sort order for this column.
-
#tag_class ⇒ Object
Gets a whitespace separated string that is used as css class for the table column.
- #td_class(record) ⇒ Object
- #th_class(record) ⇒ Object
-
#visible ⇒ Object
Gets a value indicating whether this column is visible and should be rendered or not.
-
#visible=(value) ⇒ Object
Sets a value indication whether this column is visible and should be rendered or not.
Methods inherited from Node
#attributes, #column, #columns, #columns_for, #name_chain, #root?
Constructor Details
#initialize(parent, name, options = {}) ⇒ Column
Returns a new instance of Column.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/fancygrid/column.rb', line 38 def initialize(parent, name, = {}) super(parent, name, ) @position = .fetch(:position, 0) @width = .fetch(:width, nil) @hidden = .fetch(:hidden, false) self.visible = .fetch(:visible, self.visible) @searchable = .fetch(:searchable, false) @search_value = .fetch(:search_value, nil) @search_operator = .fetch(:search_operator, nil) = .fetch(:search_options, nil) @selectable = .fetch(:selectable, false) @value_proc = .fetch(:value_proc, nil) @human_name = .fetch(:human_name, nil) @th_class = .fetch(:th_class, "") @td_class = .fetch(:td_class, "") @formatable = self.root.respond_to?(self.formatter_method) end |
Instance Attribute Details
#formatable ⇒ Object
If true, the root node has a formatter method for this column.
33 34 35 |
# File 'lib/fancygrid/column.rb', line 33 def formatable @formatable end |
#hidden ⇒ Object
If true, this column is not rendered.
12 13 14 |
# File 'lib/fancygrid/column.rb', line 12 def hidden @hidden end |
#position ⇒ Object
The column position in table.
6 7 8 |
# File 'lib/fancygrid/column.rb', line 6 def position @position end |
#search_operator ⇒ Object
The current search operator for this column.
22 23 24 |
# File 'lib/fancygrid/column.rb', line 22 def search_operator @search_operator end |
#search_options ⇒ Object
The possible search options for this column.
25 26 27 |
# File 'lib/fancygrid/column.rb', line 25 def end |
#search_value ⇒ Object
The current search value for this column.
19 20 21 |
# File 'lib/fancygrid/column.rb', line 19 def search_value @search_value end |
#searchable ⇒ Object
If true, a search field is then rendered for this column.
16 17 18 |
# File 'lib/fancygrid/column.rb', line 16 def searchable @searchable end |
#selectable ⇒ Object
If true, this column is treated as a database column. SQL queries may use the columns name for SELECT statements.
30 31 32 |
# File 'lib/fancygrid/column.rb', line 30 def selectable @selectable end |
#value_proc ⇒ Object
Value resolver proc for this column.
36 37 38 |
# File 'lib/fancygrid/column.rb', line 36 def value_proc @value_proc end |
#width ⇒ Object
The column width.
9 10 11 |
# File 'lib/fancygrid/column.rb', line 9 def width @width end |
Instance Method Details
#collect_columns(collection) ⇒ Object
Adds this column to the given collection
163 164 165 |
# File 'lib/fancygrid/column.rb', line 163 def collect_columns collection collection << self end |
#default_human_name ⇒ Object
Gets the default human name for this column
118 119 120 121 122 123 124 125 |
# File 'lib/fancygrid/column.rb', line 118 def default_human_name result = self.name.to_s.humanize if self.resource_class.respond_to? :human_attribute_name self.resource_class.human_attribute_name(self.name, :default => result) else result end end |
#fetch_value(record) ⇒ Object
Fetches a value from given record.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/fancygrid/column.rb', line 135 def fetch_value record if self.value_proc return value_proc.call(record) else chain = self.name_chain.split(".") chain.shift value = record while token = chain.shift value = (value.respond_to?(token) ? value.send(token) : nil) return nil if value.nil? end return value end end |
#fetch_value_and_format(record) ⇒ Object
Fetches a value from given record and tries to apply the format method
155 156 157 158 159 |
# File 'lib/fancygrid/column.rb', line 155 def fetch_value_and_format record value = fetch_value(record) value = self.root.send(self.formatter_method, value) if self.formatable return value end |
#formatter_method ⇒ Object
Gets the method name that is send to the root node to format the value of a column cell
85 86 87 |
# File 'lib/fancygrid/column.rb', line 85 def formatter_method @formatter_method or @formatter_method = "format_" + self.identifier.gsub(".", "_") end |
#human_name ⇒ Object
Gets the internationalized, human readable name for this column.
129 130 131 |
# File 'lib/fancygrid/column.rb', line 129 def human_name @human_name or @human_name = I18n.t(self.i18n_path, :default => default_human_name) end |
#i18n_path ⇒ Object
Gets the internationalization lookup path for this column.
112 113 114 |
# File 'lib/fancygrid/column.rb', line 112 def i18n_path @i18n_path or @i18n_path = [Fancygrid.i18n_scope, :tables, self.name_chain].join(".") end |
#identifier ⇒ Object
Gets the column identifier. This is the #table_name and #name joined with a ‘.’ (dot)
92 93 94 |
# File 'lib/fancygrid/column.rb', line 92 def identifier @identifier or @identifier = [self.table_name, self.name].join('.') end |
#sort_order ⇒ Object
Gets the current sort order for this column.
78 79 80 |
# File 'lib/fancygrid/column.rb', line 78 def sort_order self.root.view_state.column_order(self) end |
#tag_class ⇒ Object
Gets a whitespace separated string that is used as css class for the table column. The string contains the #table_name and the #name of this column.
100 101 102 |
# File 'lib/fancygrid/column.rb', line 100 def tag_class @tag_class or @tag_class = self.identifier.split(".").join(" ") end |
#td_class(record) ⇒ Object
107 108 |
# File 'lib/fancygrid/column.rb', line 107 def td_class(record) end |
#th_class(record) ⇒ Object
104 105 |
# File 'lib/fancygrid/column.rb', line 104 def th_class(record) end |
#visible ⇒ Object
Gets a value indicating whether this column is visible and should be rendered or not.
65 66 67 |
# File 'lib/fancygrid/column.rb', line 65 def visible !@hidden end |
#visible=(value) ⇒ Object
Sets a value indication whether this column is visible and should be rendered or not.
72 73 74 |
# File 'lib/fancygrid/column.rb', line 72 def visible=(value) @hidden = !value end |