Class: PhlexKit::DataTableSortHead

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/data_table/data_table_sort_head.rb

Overview

Sortable : a link cycling asc → desc → unsorted, preserving the rest of the query string (page resets). See data_table.rb.

Constant Summary collapse

ARIA_SORT =
{ "asc" => "ascending", "desc" => "descending" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(column_key:, label:, sort: nil, direction: nil, sort_param: "sort", direction_param: "direction", page_param: "page", path: "", query: {}, **attrs) ⇒ DataTableSortHead

Returns a new instance of DataTableSortHead.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/components/phlex_kit/data_table/data_table_sort_head.rb', line 5

def initialize(column_key:, label:, sort: nil, direction: nil, sort_param: "sort", direction_param: "direction", page_param: "page", path: "", query: {}, **attrs)
  @column_key = column_key
  @label = label
  @sort = sort
  @direction = direction
  @sort_param = sort_param
  @direction_param = direction_param
  @page_param = page_param
  @path = path
  @query = query.to_h.transform_keys(&:to_s)
  @attrs = attrs
end

Instance Method Details

#view_templateObject



20
21
22
23
24
25
26
27
28
29
# File 'app/components/phlex_kit/data_table/data_table_sort_head.rb', line 20

def view_template
  defaults = { class: "pk-data-table-sort-head" }
  defaults[:aria] = { sort: ARIA_SORT.fetch(current_direction) } if current_direction
  render TableHead.new(**mix(defaults, @attrs)) do
    a(href: sort_href, class: "pk-data-table-sort-link") do
      plain @label
      sort_icon
    end
  end
end