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

Add ability to set default sort order #32

Closed
yulolimum opened this issue Nov 1, 2016 · 4 comments
Closed

Add ability to set default sort order #32

yulolimum opened this issue Nov 1, 2016 · 4 comments
Milestone

Comments

@yulolimum
Copy link
Contributor

Right now, the default sort order is by id, ascending.

I've tried adding default sort order by appending query strings in the admin.html:
to: internal_intranet_news_path(@conn, :index) <> "?sort_field=inserted_at&sort_direction=desc"

Apart from breaking the "active" state of the nav link, this works great. This also works with paginated pages.

Since the active link is important, I tried to set default order by setting it in the controller:

    params = Map.put_new(params, "sort_field", "inserted_at")
    params = Map.put_new(params, "sort_direction", "desc")

This is probably cleaner, but this breaks pagination. When clicking on a pagination link, it adds the default query strings (id and asc).

Ideas?

@fire
Copy link

fire commented Feb 8, 2017

https://hexdocs.pm/torch/Torch.TableView.html#table_link/3 Adding an opt to table_link would probably be the best.

Any suggestions on how to do this?

@fire
Copy link

fire commented Feb 9, 2017

https://hexdocs.pm/torch/Torch.Controller.html#functions

In a query pipeline, use in conjunction with Ecto.Query.order_by/3:

order_by(query, ^sort(params))

@darinwilson darinwilson added this to the v1.0 milestone May 2, 2017
@morgandonze
Copy link
Contributor

Given that Torch doesn't introduce any db tables, the default order will need to be set by hardcoding when the user installs Torch or runs mix torch.gen. Correct?

@darinwilson
Copy link
Contributor

@mlaco Yep - I think we'd need to accept it as an option to mix torch.gen then have it stored in the generated controller file somehow.

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

No branches or pull requests

4 participants