From 100ed96493ddfd669cfc0aad2c22e6d940c0653e Mon Sep 17 00:00:00 2001 From: carla Date: Wed, 26 Nov 2025 18:18:27 +0100 Subject: [PATCH] feat: adds dynamic cols to table core component --- lib/mv_web/components/core_components.ex | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/mv_web/components/core_components.ex b/lib/mv_web/components/core_components.ex index 656d3c0..24e5ffe 100644 --- a/lib/mv_web/components/core_components.ex +++ b/lib/mv_web/components/core_components.ex @@ -318,6 +318,13 @@ defmodule MvWeb.CoreComponents do default: &Function.identity/1, doc: "the function for mapping each row before calling the :col and :action slots" + attr :dynamic_cols, :list, + default: [], + doc: "list of dynamic column definitions with :custom_field and :render functions" + + attr :sort_field, :any, default: nil, doc: "current sort field" + attr :sort_order, :atom, default: nil, doc: "current sort order" + slot :col, required: true do attr :label, :string end @@ -335,6 +342,16 @@ defmodule MvWeb.CoreComponents do {col[:label]} + + <.live_component + module={MvWeb.Components.SortHeaderComponent} + id={:"sort_custom_field_#{dyn_col[:custom_field].id}"} + field={"custom_field_#{dyn_col[:custom_field].id}"} + label={dyn_col[:custom_field].name} + sort_field={@sort_field} + sort_order={@sort_order} + /> + {gettext("Actions")} @@ -349,6 +366,22 @@ defmodule MvWeb.CoreComponents do > {render_slot(col, @row_item.(row))} + + {if dyn_col[:render] do + rendered = dyn_col[:render].(@row_item.(row)) + if rendered == "" do + "" + else + rendered + end + else + "" + end} +
<%= for action <- @action do %>