Module: TableHelpers
- Defined in:
- lib/table_helpers.rb
Instance Method Summary collapse
- #get_sortable_table_headers(columns = [], widths = {}) ⇒ Object
- #get_table_headers(columns = [], widths = {}) ⇒ Object
- #table_data(options = {}, &block) ⇒ Object
- #table_list(html_options = {}, &block) ⇒ Object
Instance Method Details
#get_sortable_table_headers(columns = [], widths = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/table_helpers.rb', line 22 def get_sortable_table_headers(columns=[], widths={}) headers = [] p = params i = 1 for j in 0 .. columns.length - 1 column_name = columns[j][0] sort_columns = columns[j][1..columns[j].length-1] if params[:order_by] == sort_columns.join(', ') link = link_to(column_name, p.merge('order_by' => "#{sort_columns.join(' DESC, ') + ' DESC'}"), :class=> "sortdown") elsif params[:order_by] == sort_columns.join(' DESC, ') + ' DESC' link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sortup") else link = link_to(column_name, p.merge('order_by' => sort_columns.join(', ')), :class=> "sort-none") end if widths.has_key?(i) headers.push("<th width=\"%s\">%s</th>" % [widths[i],link]) else headers.push("<th>%s</th>" % [link]) end i += 1 j += 1 end headers.join.html_safe end |
#get_table_headers(columns = [], widths = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/table_helpers.rb', line 5 def get_table_headers(columns=[], widths={}) headers = [] i = 1 for column_name in columns if widths.has_key?(i) headers.push(content_tag(:th, column_name, :width => widths[i])) else headers.push(content_tag(:th, column_name.html_safe).html_safe) end i += 1 end headers.join.html_safe end |