Module: Koi::Tables::Cells

Included in:
SummaryTableComponent, Koi::TableComponent
Defined in:
app/components/concerns/koi/tables/cells.rb,
app/components/koi/tables/cells/link_component.rb,
app/components/koi/tables/cells/attachment_component.rb

Defined Under Namespace

Classes: AttachmentComponent, LinkComponent

Instance Method Summary collapse

Instance Method Details

#attachment(column, label: nil, heading: false, variant: :thumb) {|cell| ... } ⇒ void

This method returns an undefined value.

Generates a column that renders an ActiveStorage attachment as a downloadable link.

If a block is provided, it will be called with the attachment cell component as an argument.

Examples:

Render a column containing a download link to the record’s background image

<% row.attachment :background %> # => <td><a href="...">background.png</a></td>

Parameters:

  • column (Symbol)

    the column’s name, called as a method on the record

  • label (String|nil) (defaults to: nil)

    the label to use for the column header

  • heading (boolean) (defaults to: false)

    if true, data cells will use ‘th` tags

  • variant (Symbol) (defaults to: :thumb)

    the variant to use when rendering the image (default :thumb)

  • ** (Hash)

    HTML attributes to be added to column cells

  • & (Proc)

    optional block to alter the cell content

Yield Parameters:

  • cell (Katalyst::Tables::Cells::AttachmentComponent)

    the cell component



50
51
52
53
54
# File 'app/components/concerns/koi/tables/cells.rb', line 50

def attachment(column, label: nil, heading: false, variant: :thumb, **, &)
  with_cell(Tables::Cells::AttachmentComponent.new(
              collection:, row:, column:, record:, label:, heading:, variant:, **,
            ), &)
end

This method returns an undefined value.

Generates a column that links to the record’s show page (by default).

If a block is provided, it will be called with the link cell component as an argument.

Examples:

Render a column containing the record’s title, linked to its show page

<% row.link :title %> # => <td><a href="/admin/post/15">About us</a></td>

Render a column containing the record’s title, linked to its edit page

<% row.link :title, url: :edit_admin_post_path do |cell| %>
   Edit <%= cell %>
<% end %>
# => <td><a href="/admin/post/15/edit">Edit About us</a></td>

Parameters:

  • column (Symbol)

    the column’s name, called as a method on the record

  • label (String|nil) (defaults to: nil)

    the label to use for the column header

  • heading (boolean) (defaults to: false)

    if true, data cells will use ‘th` tags

  • url (Symbol|String|Proc) (defaults to: (default_url = true))

    arguments for url_for, defaults to the record

  • link (Hash) (defaults to: {})

    options to be passed to the link_to helper

  • ** (Hash)

    HTML attributes to be added to column cells

  • & (Proc)

    optional block to alter the cell content

Yield Parameters:

  • cell (Katalyst::Tables::Cells::LinkComponent)

    the cell component



28
29
30
31
32
# File 'app/components/concerns/koi/tables/cells.rb', line 28

def link(column, label: nil, heading: false, url: (default_url = true), link: {}, **, &)
  with_cell(Tables::Cells::LinkComponent.new(
              collection:, row:, column:, record:, label:, heading:, url:, default_url:, link:, **,
            ), &)
end