Module: HyperKittenTables::Concerns::Table

Extended by:
ActiveSupport::Concern
Included in:
HyperKittenTables::Components::Table
Defined in:
lib/hyper_kitten_tables/concerns/table.rb

Instance Method Summary collapse

Instance Method Details

#define_header_sort_url(&block) ⇒ Object



40
41
42
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 40

def define_header_sort_url(&block)
  define_singleton_method(:header_sort_url, &block)
end


50
51
52
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 50

def footer(&block)
  @footer = block
end

#header_sort_url(column, query_params) ⇒ Object

Raises:

  • (NotImplementedError)


44
45
46
47
48
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 44

def header_sort_url(column, query_params)
  # Override this method to define the sort url for the header.

  raise NotImplementedError, "You must define #header_sort_url if you want sortable table columns."
end

#initialize(collection: [], requested_columns: []) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 17

def initialize(collection: [], requested_columns: [], &block)
  @collection = collection
  @columns = []

  @table_options = {}
  @thead_options = {}
  @tbody_options = {}
  @tr_options = {}
  @th_options = {}

  @requested_columns = requested_columns
  yield self if block_given?
end

#render_in(view_context) ⇒ Object



74
75
76
77
78
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 74

def render_in(view_context)
  @view_context = view_context

  render_table
end

#table(**options) ⇒ Object



54
55
56
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 54

def table(**options)
  @table_options = options
end

#tbody(**options) ⇒ Object



58
59
60
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 58

def tbody(**options)
  @tbody_options = options
end

#td(name, method_name: nil, sort_key: nil, sortable: true, **options, &block) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 31

def td(name, method_name: nil, sort_key: nil, sortable: true, **options, &block)
  if method_name.nil?
    method_name = name.to_s.parameterize.underscore
    name = name.to_s.titleize unless block_given?
  end
  sort_key = method_name if sort_key.blank?
  @columns << Column.new(name, method_name, sort_key, block, sortable, options)
end

#th(**options) ⇒ Object



70
71
72
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 70

def th(**options)
  @th_options = options
end

#thead(**options) ⇒ Object



62
63
64
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 62

def thead(**options)
  @thead_options = options
end

#tr(**options) ⇒ Object



66
67
68
# File 'lib/hyper_kitten_tables/concerns/table.rb', line 66

def tr(**options)
  @tr_options = options
end