Class: ActiveAdmin::Views::TableFor

Inherits:
Arbre::HTML::Table
  • Object
show all
Defined in:
lib/active_admin/views/components/table_for.rb

Direct Known Subclasses

IndexAsTable::IndexTableFor

Defined Under Namespace

Classes: Column

Instance Method Summary collapse

Instance Method Details

#build(obj, *attrs) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/active_admin/views/components/table_for.rb', line 11

def build(obj, *attrs)
  options = attrs.extract_options!
  @sortable = options.delete(:sortable)
  @collection = obj.respond_to?(:each) && !obj.is_a?(Hash) ? obj : [obj]
  @resource_class = options.delete(:i18n)
  @resource_class ||= @collection.klass if @collection.respond_to? :klass

  @columns = []
  @row_class = options.delete(:row_class)

  build_table
  super(options)
  columns(*attrs)
end

#column(*args, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_admin/views/components/table_for.rb', line 30

def column(*args, &block)
  options = default_options.merge(args.extract_options!)
  title = args[0]
  data = args[1] || args[0]

  col = Column.new(title, data, @resource_class, options, &block)
  @columns << col

  # Build our header item
  within @header_row do
    build_table_header(col)
  end

  # Add a table cell for each item
  @collection.each_with_index do |resource, index|
    within @tbody.children[index] do
      build_table_cell col, resource
    end
  end
end

#columns(*attrs) ⇒ Object



26
27
28
# File 'lib/active_admin/views/components/table_for.rb', line 26

def columns(*attrs)
  attrs.each { |attr| column(attr) }
end

#sortable?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/active_admin/views/components/table_for.rb', line 51

def sortable?
  !!@sortable
end

#tag_nameObject



7
8
9
# File 'lib/active_admin/views/components/table_for.rb', line 7

def tag_name
  "table"
end