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

SelectAssoc options custom sort #3

Open
jaysson opened this issue Feb 14, 2018 · 2 comments
Open

SelectAssoc options custom sort #3

jaysson opened this issue Feb 14, 2018 · 2 comments

Comments

@jaysson
Copy link

jaysson commented Feb 14, 2018

Looks like the option labels are sorted alphabetically.

|> Enum.sort(fn {name1, _}, {name2, _} ->

How do I sort by a column?

** Context
I have a multi level/nested set of categories. These can be selected at any level using a SelectAssoc field.

Data

Deserts
-- Gluten Free
-- Vegetarian
Mains
-- Chicken

Form

|> add(
  :categories,
  SelectAssoc,
  label: "Categories",
  choice_label: fn category ->
    if category.parent_id do
      "-- #{category.name}"
    else
      category.name
    end
  end,
  query: fn query ->
    from c in query,
    order_by: [asc: :sort_value]
  end,
  validation: [:required]
)

However, it displays like this:

-- Gluten Free
-- Vegetarian
-- Chicken
Deserts
Mains
@jakub-zawislak
Copy link
Owner

jakub-zawislak commented Feb 15, 2018

Maybe you can make use of group_by option?
Anyway, custom sorting in selects is the must have in this library

@jaysson
Copy link
Author

jaysson commented Feb 19, 2018

I did not need many to many relation, thus I could replace it with a simple select field with choices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants