Class: View::Table
Overview
Renders a table.
It uses a partial, which you can find in the gem under app/views/shared/_table.html.erb (and haml).
To change the table layout, you can copy the partial to your own application.
You can use a block to format attributes, or you can specify them with the fields option and trust them to be properly formatted automatically.
If you don't provide a block or fields, it will try to detect your fields automatically.
Use the partial option to render a different table partial.
When you use :as => :link, it will link to the record, or you specify the path option. Please see the documentation of View::Link for more information.
You will need to specify the class option to get a proper table headers when the collection is empty.
Defined Under Namespace
Instance Attribute Summary
Attributes inherited from Formatter
Instance Method Summary (collapse)
-
- (Array) columns
The columns defined.
-
- (Object) each {|Row| ... }
Iterates over the collection and yields rows.
- - (Object) resource_class
-
- (Object) view(attribute, options = {}) {|formatter| ... }
This will add the th and td tags.
Methods inherited from Formatter
#all_options, as, inherited, #options, skip_blank_formatter, #to_s, type
Instance Method Details
- (Array) columns
The columns defined
72 73 74 |
# File 'lib/view/formatters/table.rb', line 72 def columns @columns ||= [] end |
- (Object) each {|Row| ... }
Iterates over the collection and yields rows.
78 79 80 81 82 |
# File 'lib/view/formatters/table.rb', line 78 def each value.each_with_index do |resource, index| yield Row.new(resource, self, index) end end |
- (Object) resource_class
84 85 86 |
# File 'lib/view/formatters/table.rb', line 84 def resource_class [:class] || value.first.class end |
- (Object) view(attribute, options = {}) {|formatter| ... }
This will add the th and td tags.
65 66 67 68 |
# File 'lib/view/formatters/table.rb', line 65 def view(attribute, = {}, &block) columns << Column.new(attribute, , block, self) nil end |