Module: Katalyst::Tables::Selectable

Extended by:
ActiveSupport::Concern
Defined in:
app/components/concerns/katalyst/tables/selectable.rb,
app/components/katalyst/tables/selectable/form_component.rb

Overview

Adds checkbox selection to a table. See [documentation](/docs/selectable.md) for more details.

Defined Under Namespace

Classes: FormComponent

Constant Summary collapse

FORM_CONTROLLER =
"tables--selection--form"
TABLE_CONTROLLER =
"tables--selection--table"
ITEM_CONTROLLER =
"tables--selection--item"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_form_id(collection) ⇒ Object

Returns the default dom id for the selection form, uses the table’s default id with ‘_selection’ appended.



16
17
18
# File 'app/components/concerns/katalyst/tables/selectable.rb', line 16

def self.default_form_id(collection)
  "#{Identifiable::Defaults.default_table_id(collection)}_selection_form"
end

Instance Method Details

#select(params: { id: record&.id }, form_id: Selectable.default_form_id(collection)) ⇒ void

This method returns an undefined value.

Adds the selection column to the table

Examples:

Render a select column

<% row.select %> # => <td><input type="checkbox" ...></td>

Parameters:

  • params (Hash) (defaults to: { id: record&.id })

    params to pass to the controller for selected rows

  • form_id (String) (defaults to: Selectable.default_form_id(collection))

    id of the form element that will submit the selected row params

  • ** (Hash)

    HTML attributes to be added to column cells

  • & (Proc)

    optional block to alter the cell content



30
31
32
33
34
35
36
# File 'app/components/concerns/katalyst/tables/selectable.rb', line 30

def select(params: { id: record&.id }, form_id: Selectable.default_form_id(collection), **, &)
  update_html_attributes(**table_selection_attributes(form_id:)) if header?

  with_cell(Cells::SelectComponent.new(
              collection:, row:, column: :_select, record:, label: "", heading: false, params:, form_id:, **,
            ), &)
end