Module: Datagrid::Columns::ClassMethods
- Defined in:
- lib/datagrid/columns.rb
Overview
self.included
Instance Method Summary collapse
-
#column(name, options = {}, &block) ⇒ Object
Defines new datagrid column.
- #column_by_name(name) ⇒ Object
-
#columns(*args) ⇒ Object
Returns a list of columns defined.
- #inherited(child_class) ⇒ Object
Instance Method Details
#column(name, options = {}, &block) ⇒ Object
Defines new datagrid column
42 43 44 45 46 47 48 |
# File 'lib/datagrid/columns.rb', line 42 def column(name, = {}, &block) check_scope_defined!("Scope should be defined before columns") block ||= lambda do |model| model.send(name) end columns_array << Datagrid::Columns::Column.new(self, name, , &block) end |
#column_by_name(name) ⇒ Object
50 51 52 53 54 |
# File 'lib/datagrid/columns.rb', line 50 def column_by_name(name) self.columns.find do |col| col.name.to_sym == name.to_sym end end |
#columns(*args) ⇒ Object
Returns a list of columns defined. All column definistion are returned by default You can limit the output with only columns you need like:
grid.columns(:id, :name)
Supported options:
-
:data - if true returns only non-html columns. Default: false.
32 33 34 35 36 37 38 39 |
# File 'lib/datagrid/columns.rb', line 32 def columns(*args) = args. args.compact! args.map!(&:to_sym) columns_array.select do |column| (![:data] || column.data?) && (args.empty? || args.include?(column.name)) end end |
#inherited(child_class) ⇒ Object
56 57 58 59 |
# File 'lib/datagrid/columns.rb', line 56 def inherited(child_class) super(child_class) child_class.columns_array = self.columns_array.clone end |