Sha256: bae0e585e5eca2e80ca465de5e88a6a09ec55bf68828dfc5af014f91b237c480

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Katalyst
  module Tables
    # Adds checkbox selection to a table.
    # See [documentation](/docs/selectable.md) for more details.
    module Selectable
      extend ActiveSupport::Concern

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

      # Returns the default dom id for the selection form, uses the table's
      # default id with '_selection' appended.
      def self.default_form_id(collection)
        "#{Identifiable::Defaults.default_table_id(collection)}_selection_form"
      end

      # Adds the selection column to the table
      #
      # @param params [Hash] params to pass to the controller for selected rows
      # @param form_id [String] id of the form element that will submit the selected row params
      # @param ** [Hash] HTML attributes to be added to column cells
      # @param & [Proc] optional block to alter the cell content
      # @return [void]
      #
      # @example Render a select column
      #   <% row.select %> # => <td><input type="checkbox" ...></td>
      def select(params: { id: record&.id }, form_id: Selectable.default_form_id(collection), **, &)
        with_cell(Cells::SelectComponent.new(
                    collection:, row:, column: :_select, record:, label: "", heading: false, params:, form_id:, **,
                  ), &)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
katalyst-tables-3.3.4 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.3.3 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.3.2 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.3.1 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.3.0 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.2.0 app/components/concerns/katalyst/tables/selectable.rb
katalyst-tables-3.1.0 app/components/concerns/katalyst/tables/selectable.rb