Module: SortableHelper
- Defined in:
- lib/sortable_helper.rb
Instance Method Summary collapse
- #build_url_params(action, param, params, extra_params = {}) ⇒ Object
- #mouseover_pointer ⇒ Object
- #row_cell_link(new_location) ⇒ Object
- #sort_link_helper(action, text, param, params, extra_params = {}) ⇒ Object
- #sort_td_class_helper(param) ⇒ Object
-
#sortable_table(options = {}) ⇒ Object
Helper method to generate a sortable table in the view.
- #table_header ⇒ Object
Instance Method Details
#build_url_params(action, param, params, extra_params = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sortable_helper.rb', line 45 def build_url_params(action, param, params, extra_params={}) key = param if @default_sort_key && @default_sort == param key = @default_sort_key else key += "_reverse" if params[:sort] == param end params = {:sort => key, :page => nil, # when sorting we start over on page 1 :q => params[:q]} params.merge!(extra_params) return {:action => action, :params => params} end |
#mouseover_pointer ⇒ Object
64 65 66 |
# File 'lib/sortable_helper.rb', line 64 def mouseover_pointer "onmouseover='this.style.cursor = \"pointer\"' onmouseout='this.style.cursor=\"auto\"'" end |
#row_cell_link(new_location) ⇒ Object
60 61 62 |
# File 'lib/sortable_helper.rb', line 60 def row_cell_link(new_location) mouseover_pointer + "onclick='window.location=\"#{new_location}\"'" end |
#sort_link_helper(action, text, param, params, extra_params = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/sortable_helper.rb', line 38 def sort_link_helper(action, text, param, params, extra_params={}) = build_url_params(action, param, params, extra_params) = {:title => "Sort by this field"} link_to(text, , ) end |
#sort_td_class_helper(param) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/sortable_helper.rb', line 30 def sort_td_class_helper(param) result = 'sortup' if params[:sort] == param result = 'sortdown' if params[:sort] == param + "_reverse" result = @sortclass if @default_sort && @default_sort == param return result end |
#sortable_table(options = {}) ⇒ Object
Helper method to generate a sortable table in the view
usage: <%= sortable_table(optional_params) %>
optional_params:
:paginate - Whether or not to display pagination links for the table. Default is true. :partial - Name of the partial containing the table to display. Default is the table partial in the sortable
plugin: 'sortable/table'
If you choose to create your own partial in place of the one distributed with the sortable plugin
your partial has the following available to it for generating the table:
@headings contains the table heading values
@objects contains the collection of objects to be displayed in the table
:search - Whether or not to include a search field for the table. Default is true.
19 20 21 22 23 24 25 26 27 |
# File 'lib/sortable_helper.rb', line 19 def sortable_table(={}) paginate = [:paginate].nil? ? true : [:paginate] partial = [:partial].nil? ? 'sortable/table' : [:partial] search = [:search].nil? ? true : [:search] result = render(:partial => partial, :locals => {:search => search}) result += will_paginate(@objects).to_s if paginate result end |
#table_header ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sortable_helper.rb', line 68 def table_header result = "<tr class='tableHeaderRow'>" @headings.each do |heading| sort_class = sort_td_class_helper heading[1] result += "<td" result += " class='#{sort_class}'" if !sort_class.blank? result += ">" result += sort_link_helper @action, heading[0], heading[1], params result += "</td>" end result += "</tr>" return result end |