Module: Trestle::SortHelper
- Defined in:
- app/helpers/trestle/sort_helper.rb
Defined Under Namespace
Classes: SortLink
Instance Method Summary collapse
-
#sort_link(text, field, **options) ⇒ Object
Renders a sort link for a table column header.
Instance Method Details
#sort_link(text, field, **options) ⇒ Object
Renders a sort link for a table column header.
The sort and order params are used to determine whether the sort link is
active, and which is the current sort direction (asc or desc). CSS classes are
applied accordingly which are used to render the appropriate icons alongside the link.
The current set of persistent_params is merged with the new sort/order params
to build the target link URL.
text - Text or HTML content to render as the link label
field - The name of the current field, which should match the sort param
when the collection is being sorted by this field
options - Hash of options (default: {}):
:default - (Boolean) Set to true if the field is considered to be active
even when the sort param is blank (default: false)
:default_order - (String/Symbol) Specify the default collection order when
the order param is blank (default: "asc")
Examples
<%= sort_link "Title", :title, default: true %>
<%= sort_link "Created", :created_at, default_order: "desc" %>
Returns a HTML-safe String.
28 29 30 31 |
# File 'app/helpers/trestle/sort_helper.rb', line 28 def sort_link(text, field, **) sort_link = SortLink.new(field, persistent_params, **) link_to text, sort_link.params, class: sort_link.classes end |