Module: DryCrud::Table::Sorting

Included in:
Builder
Defined in:
app/helpers/dry_crud/table/sorting.rb

Overview

Provides headers with sort links. Expects a method :sortable?(attr) in the template/controller to tell if an attribute is sortable or not. Extracted into an own module for convenience.

Instance Method Summary collapse

Instance Method Details

#sort_header(attr, label = nil) ⇒ Object

Create a header with sort links and a mark for the current sort direction.


11
12
13
14
# File 'app/helpers/dry_crud/table/sorting.rb', line 11

def sort_header(attr, label = nil)
  label ||= attr_header(attr)
  template.link_to(label, sort_params(attr)) + current_mark(attr)
end

#sortable_attr(attr, header = nil, &block) ⇒ Object

Renders a sort link header, otherwise similar to :attr.


23
24
25
26
27
28
29
# File 'app/helpers/dry_crud/table/sorting.rb', line 23

def sortable_attr(attr, header = nil, &block)
  if template.sortable?(attr)
    attr(attr, sort_header(attr, header), &block)
  else
    attr(attr, header, &block)
  end
end

#sortable_attrs(*attrs) ⇒ Object

Same as :attrs, except that it renders a sort link in the header if an attr is sortable.


18
19
20
# File 'app/helpers/dry_crud/table/sorting.rb', line 18

def sortable_attrs(*attrs)
  attrs.each { |a| sortable_attr(a) }
end