Module: Cheveret::Table::Sorting
- Included in:
- Base
- Defined in:
- lib/cheveret/table/sorting.rb
Defined Under Namespace
Modules: ClassMethods, Sortable
Instance Attribute Summary collapse
-
#sort_column ⇒ Object
Returns the value of attribute sort_column.
-
#sort_direction ⇒ Object
Returns the value of attribute sort_direction.
- #sort_param ⇒ Object
-
#sort_url ⇒ Object
Returns the value of attribute sort_url.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#sort_column ⇒ Object
Returns the value of attribute sort_column.
37 38 39 |
# File 'lib/cheveret/table/sorting.rb', line 37 def sort_column @sort_column end |
#sort_direction ⇒ Object
Returns the value of attribute sort_direction.
37 38 39 |
# File 'lib/cheveret/table/sorting.rb', line 37 def sort_direction @sort_direction end |
#sort_param ⇒ Object
82 83 84 |
# File 'lib/cheveret/table/sorting.rb', line 82 def sort_param @sort_param end |
#sort_url ⇒ Object
Returns the value of attribute sort_url.
37 38 39 |
# File 'lib/cheveret/table/sorting.rb', line 37 def sort_url @sort_url end |
Class Method Details
.included(base) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/cheveret/table/sorting.rb', line 28 def self.included(base) base.module_eval do extend ClassMethods end # make sure our column objects can be configured as sortable ::Cheveret::Column.send :include, Sortable end |
Instance Method Details
#render_th(column, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/cheveret/table/sorting.rb', line 89 def render_th(column, ={}) return super unless column.sortable? [:class] = [ 'sortable', *[:class] ] [:class] << 'sorted' if column.name == sort_column [:class].flatten.join(' ').strip super end |
#table_header(column) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/cheveret/table/sorting.rb', line 102 def table_header(column) # wrap unsortable columns in a <span> tag return template.content_tag(:span, super) unless column.sortable? column_key = sort_param % 'sort_column' direction_key = sort_param % 'sort_direction' attrs = {} query = { column_key => column.name, direction_key => column.default_sort_direction } if column.name == sort_column query[direction_key] = ( sort_direction == :asc ? :desc : :asc ) attrs[:class] = "#{sort_direction}" end attrs[:href] = template.url_for(sort_url.merge(query)) template.content_tag(:a, super, attrs) end |