Module: Katalyst::Tables::Frontend

Included in:
Query::ModalComponent, QueryComponent
Defined in:
app/helpers/katalyst/tables/frontend.rb

Overview

View Helper for generating HTML tables. Include in your ApplicationHelper, or similar.

Instance Method Summary collapse

Instance Method Details

#summary_table_with(model:) {|the, nil| ... } ⇒ Object

Construct a new summary table component.

Blocks will receive the table in row-rendering mode (with row and record defined):

Parameters:

  • model (ActiveRecord::Base)

    subject for the table

Yield Parameters:

  • the (Katalyst::TableComponent)

    table component to render rows

  • nil (nil, Object)

    for the header column, or the given model for the value column



82
83
84
85
86
87
# File 'app/helpers/katalyst/tables/frontend.rb', line 82

def summary_table_with(model:, **, &)
  component ||= default_summary_table_component_class
  component = component.new(model:, **)

  render(component, &)
end

#table_orderable_with(collection:, url:, id: nil, scope: nil) ⇒ Object

Parameters:

  • collection (Katalyst::Tables::Collection::Core)

    the collection to render

  • url (String)

    the url to submit the form to (e.g. <resources>_order_path)

  • id (String) (defaults to: nil)

    the id of the form element (defaults to <resources>_order_form)

  • scope (String) (defaults to: nil)

    the base scope to use for form inputs (defaults to order)



47
48
49
# File 'app/helpers/katalyst/tables/frontend.rb', line 47

def table_orderable_with(collection:, url:, id: nil, scope: nil, &)
  render(Orderable::FormComponent.new(collection:, url:, id:, scope:))
end

#table_pagination_with(collection:) ⇒ Object

Construct pagination navigation for the current page. Defaults to pagy_nav.

Parameters:



61
62
63
64
# File 'app/helpers/katalyst/tables/frontend.rb', line 61

def table_pagination_with(collection:, **)
  component ||= default_table_pagination_component_class
  render(component.new(collection:, **))
end

#table_query_with(collection:, url: url_for, component: nil) ⇒ Object

Construct a new query interface for filtering the current page.

Parameters:

  • collection (Katalyst::Tables::Collection::Core)

    the collection to render

  • url (String) (defaults to: url_for)

    the url to submit the form to (e.g. <resources>_path)



70
71
72
73
# File 'app/helpers/katalyst/tables/frontend.rb', line 70

def table_query_with(collection:, url: url_for, component: nil, &)
  component ||= default_table_query_component_class
  render(component.new(collection:, url:), &)
end

#table_selection_with(collection:, id: nil, primary_key: :id) ⇒ Object

Parameters:

  • collection (Katalyst::Tables::Collection::Core)

    the collection to render

  • id (String) (defaults to: nil)

    the id of the form element (defaults to <resources>_selection_form)

  • primary_key (String) (defaults to: :id)

    the primary key of the record in the collection (defaults to :id)



54
55
56
# File 'app/helpers/katalyst/tables/frontend.rb', line 54

def table_selection_with(collection:, id: nil, primary_key: :id, &)
  render(Selectable::FormComponent.new(collection:, id:, primary_key:), &)
end

#table_with(collection:, component: nil, header: true, caption: true, generate_ids: false, object_name: nil, partial: nil, as: nil) {|the, the| ... } ⇒ Object

Construct a new table component. This entry point supports a large number of options for customizing the table. The most common options are: Blocks will receive the table in row-rendering mode (with row and record defined): If no block is provided when the table is rendered then the table will look for a row partial: In addition to these options, standard HTML attributes can be passed which will be added to the table tag.

Parameters:

  • collection (Katalyst::Tables::Collection::Core)

    the collection to render

  • header (Boolean) (defaults to: true)

    whether to render the header row (defaults to true, supports options)

  • caption (Boolean Hash) (defaults to: true)

    whether to render the caption (defaults to true, supports options)

  • generate_ids (Boolean) (defaults to: false)

    whether to generate dom ids for the table and rows

  • object_name (Symbol) (defaults to: nil)

    the name of the object to use for partial rendering (defaults to collection.model_name.i18n_key)

  • partial (String) (defaults to: nil)

    the name of the partial to use for rendering each row (defaults to to_partial_path on the object)

  • as (Symbol) (defaults to: nil)

    the name of the local variable to use for rendering each row (defaults to collection.model_name.param_key)

Yield Parameters:

  • the (Katalyst::TableComponent)

    row component to render

  • the (Object, nil)

    object to render, or nil for header rows



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/katalyst/tables/frontend.rb', line 27

def table_with(collection:,
               component: nil,
               header: true,
               caption: true,
               generate_ids: false,
               object_name: nil,
               partial: nil,
               as: nil,
               **,
               &)
  component ||= default_table_component_class
  component = component.new(collection:, header:, caption:, generate_ids:, object_name:, partial:, as:, **)

  render(component, &)
end