MishkaGervaz.Table.Behaviours.ColumnType behaviour (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Behaviour for column type renderers.

Implement this behaviour to create custom column types that render values in specific ways (badges, links, colors, etc.).

Example

defmodule MyApp.ColumnTypes.Color do
  @behaviour MishkaGervaz.Table.Behaviours.ColumnType
  use Phoenix.Component

  @impl true
  def render(value, _column, _record, _ui) do
    assigns = %{value: value}

    ~H"""
    <div class="w-6 h-6 rounded" style={"background: #{@value}"}></div>
    """
  end
end

Then use in DSL:

column :background_color, type: MyApp.ColumnTypes.Color

See MishkaGervaz.Table.Types.Column (registry), MishkaGervaz.Table.Entities.Column, and MishkaGervaz.Table.Behaviours.TypeRegistry.

Summary

Callbacks

Optional: Return CSS class for the cell.

Render the column cell value.

Callbacks

cell_class(column)

(optional)
@callback cell_class(column :: map()) :: String.t() | nil

Optional: Return CSS class for the cell.

render(value, column, record, ui)

@callback render(
  value :: any(),
  column :: map(),
  record :: map(),
  ui :: module()
) :: Phoenix.LiveView.Rendered.t()

Render the column cell value.

Parameters

  • value - The value to render (extracted from record based on column source)
  • column - Column configuration map from DSL
  • record - The full record (for accessing other fields if needed)
  • ui - UI adapter module for consistent styling

Returns

Phoenix.LiveView.Rendered.t()