Module: Filterrific::ActionViewExtension
- Includes:
- HasResetFilterrificUrlMixin
- Defined in:
- lib/filterrific/action_view_extension.rb
Instance Method Summary collapse
-
#filterrific_sorting_link(filterrific, sort_key, opts = {}) ⇒ Object
Renders a link which indicates the current sorting and which can be used to toggle the list sorting (set column and direction).
-
#form_for_filterrific(record, options = {}, &block) ⇒ Object
Sets all options on form_for to defaults that work with Filterrific.
-
#render_filterrific_spinner ⇒ Object
Renders a spinner while the list is being updated.
Methods included from HasResetFilterrificUrlMixin
Instance Method Details
#filterrific_sorting_link(filterrific, sort_key, opts = {}) ⇒ Object
Renders a link which indicates the current sorting and which can be used to toggle the list sorting (set column and direction).
NOTE: Make sure that this is used in the list partial that is re-rendered when the filterrific params are changed, so that the filterrific params in the URL are always current.
NOTE: Currently the filterrific_sorting_link is not synchronized with a SELECT input you may have in the filter form for sorting. We recommend you use one or the other to avoid conflicting sort settings in the UI.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/filterrific/action_view_extension.rb', line 64 def filterrific_sorting_link(filterrific, sort_key, opts = {}) opts = { active_column_class: "filterrific_current_sort_column", inactive_column_class: "filterrific_sort_column", ascending_indicator: "⬆", default_sort_direction: "asc", descending_indicator: "⬇", html_attrs: {}, label: sort_key.to_s.humanize, sorting_scope_name: :sorted_by, url_for_attrs: {}, as: :filterrific }.merge(opts) opts.merge!( html_attrs: opts[:html_attrs].with_indifferent_access, current_sorting: (current_sorting = filterrific.send(opts[:sorting_scope_name])), current_sort_key: current_sorting ? current_sorting.gsub(/_asc|_desc/, "") : nil, current_sort_direction: if current_sorting current_sorting.end_with?("_desc") ? "desc" : "asc" end, current_sort_direction_indicator: if current_sorting (current_sorting.end_with?("_desc") ? opts[:descending_indicator] : opts[:ascending_indicator]) end ) new_sort_key = sort_key.to_s if new_sort_key == opts[:current_sort_key] # same sort column, reverse order filterrific_sorting_link_reverse_order(filterrific, new_sort_key, opts) else # new sort column, default sort order filterrific_sorting_link_new_column(filterrific, new_sort_key, opts) end end |
#form_for_filterrific(record, options = {}, &block) ⇒ Object
Sets all options on form_for to defaults that work with Filterrific
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/filterrific/action_view_extension.rb', line 12 def form_for_filterrific(record, = {}, &block) [:as] ||= :filterrific [:html] ||= {} [:html][:method] ||= :get [:html][:id] ||= :filterrific_filter [:url] ||= url_for( controller: controller.controller_name, action: controller.action_name ) form_for(record, , &block) end |
#render_filterrific_spinner ⇒ Object
Renders a spinner while the list is being updated
25 26 27 28 29 30 31 |
# File 'lib/filterrific/action_view_extension.rb', line 25 def render_filterrific_spinner %( <span class="filterrific_spinner" style="display:none;"> #{image_tag("filterrific/filterrific-spinner.gif", alt: "", role: "presentation")} </span> ).html_safe end |