Module: Katalyst::Tables::Orderable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/components/concerns/katalyst/tables/orderable.rb,
app/components/katalyst/tables/orderable/form_component.rb
Overview
Adds drag and drop ordering to a table. See [documentation](/docs/orderable.md) for more details.
Defined Under Namespace
Classes: FormComponent
Constant Summary collapse
- FORM_CONTROLLER =
"tables--orderable--form"
- ITEM_CONTROLLER =
"tables--orderable--item"
- LIST_CONTROLLER =
"tables--orderable--list"
Class Method Summary collapse
-
.default_form_id(collection) ⇒ Object
Returns the default dom id for the selection form, uses the table’s default id with ‘_selection’ appended.
-
.default_scope(collection) ⇒ Object
Generate a form input ‘name’ for param updates for a given record and attribute.
-
.record_scope(id, attribute) ⇒ Object
Generate a nested scope for for param updates for a given record and attribute.
Instance Method Summary collapse
-
#ordinal(column = :ordinal, primary_key: :id) ⇒ void
Generates a column for the user to drag and drop to reorder data rows.
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/orderable.rb', line 16 def self.default_form_id(collection) "#{Identifiable::Defaults.default_table_id(collection)}_order_form" end |
.default_scope(collection) ⇒ Object
Generate a form input ‘name’ for param updates for a given record and attribute.
21 22 23 |
# File 'app/components/concerns/katalyst/tables/orderable.rb', line 21 def self.default_scope(collection) "order[#{collection.model_name.plural}]" end |
.record_scope(id, attribute) ⇒ Object
Generate a nested scope for for param updates for a given record and attribute. Will be concatenated with the form’s scope in the browser.
27 28 29 |
# File 'app/components/concerns/katalyst/tables/orderable.rb', line 27 def self.record_scope(id, attribute) "[#{id}][#{attribute}]" end |
Instance Method Details
#ordinal(column = :ordinal, primary_key: :id) ⇒ void
This method returns an undefined value.
Generates a column for the user to drag and drop to reorder data rows.
41 42 43 44 45 46 47 |
# File 'app/components/concerns/katalyst/tables/orderable.rb', line 41 def ordinal(column = :ordinal, primary_key: :id, **, &) initialize_orderable if row.header? with_cell(Cells::OrdinalComponent.new( collection:, row:, column:, record:, label: "", heading: false, primary_key:, **, ), &) end |