petal_components
petal_components copied to clipboard
Data Table - Does sortable support embedded schemas?
I was wondering if the data table component supports sorting embedded schema fields. I have an embedded schema called "metrics" and want make its fields be sortable in a table called "assets". If not, then I think it would cool to have the sortable attribute to have the option to accept an embedded field name for example sortable={:embedded_field_name}
defmodule Metrics do
use Ecto.Schema
embedded_schema do
field :cost_basis, :float, default: 0.0
field :value, :float, default: 0.0
field :capital_gain, :float, default: 0.0
end
end
defmodule Assets do
schema "assets" do
embeds_one(:metrics, Metrics)
timestamps()
end
end
<.data_table :if={@index_params} meta={@meta} items={@assets}>
<:if_empty>No assets found</:if_empty>
<:col field={:label} sortable />
# if sortable does not support embedded schema, then sortable={:embedded_field_name} would be cool to support this syntax
<:col :let={asset} field={:metrics} sortable={:cost_basis}>
<%= asset.metrics.cost_basis %>
</:col>
</.data_table>