Module: Datagrid::Columns::ClassMethods

Defined in:
lib/datagrid/columns.rb

Overview

self.included

Instance Method Summary collapse

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, options = {}, &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, options, &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)
  options = args.extract_options!
  args.compact!
  args.map!(&:to_sym)
  columns_array.select do |column|
    (!options[: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