Skip to content

Commit

Permalink
Add optional custom row classes and enable removal of odd-even classes [
Browse files Browse the repository at this point in the history
  • Loading branch information
jesjos committed Mar 21, 2013
1 parent ecf8342 commit f024c74
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/tabletastic/table_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TableBuilder

def initialize(collection, klass, template)
@collection, @klass, @template = collection, klass, template
@produce_rowclass = lambda {|template, record| template.cycle("odd", "even") }
@table_fields = []
end

Expand Down Expand Up @@ -77,7 +78,7 @@ def head
def body
content_tag(:tbody) do
@collection.inject("\n") do |rows, record|
rowclass = @template.cycle("odd","even")
rowclass = @produce_rowclass.call(@template, record)
rows += @template.content_tag_for(:tr, record, :class => rowclass) do
cells_for_row(record)
end + "\n"
Expand Down Expand Up @@ -121,6 +122,18 @@ def action_link(action, prefix)
self.cell(action, :heading => "", :cell_html => {:class => html_class}, &block)
end

def row_class(*args, &block)
options = args.extract_options!
css_block = block || lambda { |resource| args.first }
if options.fetch(:odd_even, true)
@produce_rowclass = lambda do |template, resource|
[template.cycle("odd", "even"), css_block.call(resource)].join(" ")
end
else
@produce_rowclass = lambda {|template, resource| css_block.call(resource)}
end
end

protected

def orm_fields
Expand Down

0 comments on commit f024c74

Please sign in to comment.