Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Table - Does sortable support embedded schemas? #214

Open
safari12 opened this issue Jun 22, 2023 · 2 comments
Open

Data Table - Does sortable support embedded schemas? #214

safari12 opened this issue Jun 22, 2023 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@safari12
Copy link

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>
@mplatts
Copy link
Contributor

mplatts commented Jun 26, 2023

Sorry my head is deep in another topic at the moment so I'm not sure off the top of my head. We use https://github.com/woylie/flop underneath - so if you can find a way for that to filter by embedded schema fields, then I can better answer how to replicate in our data table.

@safari12
Copy link
Author

Gotcha sounds good, I'll investigate the flop library

@nhobes nhobes added the help wanted Extra attention is needed label Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants