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
endThen use in DSL:
column :background_color, type: MyApp.ColumnTypes.ColorSee MishkaGervaz.Table.Types.Column (registry),
MishkaGervaz.Table.Entities.Column, and
MishkaGervaz.Table.Behaviours.TypeRegistry.
Summary
Callbacks
Optional: Return CSS class for the cell.
@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 DSLrecord- The full record (for accessing other fields if needed)ui- UI adapter module for consistent styling
Returns
Phoenix.LiveView.Rendered.t()