Skip to content

Loading…

Can't manage the order of the query for index page #1317

Closed
keysen opened this Issue · 7 comments

3 participants

@keysen

Hello,

I've try to set an order to display the informations, It works if a write a default_scope method in my model, but it's a real problem to do this because after modify the default_scope it become impossible to use a custom order in all my futur query.

I've read a lot of think like the sort_order which is available in activeadmin DSL, but It's not really the order of the query but the order of a specific column in my list, in my case I must sort between 2 models associated by a foreign key. I can do this with a query by using MyModel.includes(:second_model).order("current_model.attribute1 asc", "second_model.attribute2 desc")

How can I do this ?
I've try to override the collection method but without success... I've tried some scope but in a resource file of activeadmin I can't use order in a scope it doesn't work and doesn't do what I've searching for.

Thanks a lot for your help.

@j-manu

From what In understood of your issue, you should be able to resolve it by using a scope in your activeadmin resource config with the default attribute set. Like this - https://github.com/gregbell/demo.activeadmin.info/blob/master/app/admin/orders.rb#L7

if this is not what you are looking for, please ask in the mailing list. Github issues are only for bugs.

@j-manu j-manu closed this
@keysen

It's not what i'm looking for :s, but there is a issue with scope it doesn't change the order of elements in index page !

If I do :
scope :test, default: true do |t|
t.order("attribute DESC")
end

It seems to be a bug even though we can do this with a sort_order, the the sort_order is not so complete it doesn't give possibility to sort between models associated and their attributes.

@j-manu

That works for me. Which version are you using?

@pcreux

@keysen Do you know about #reorder? :)

@keysen

Thank you for this information, indeed I didn't know reorder :). Thanks a lot.

I've successfully sort my index page with a reorder because a simple order doesn't works, but after this it's became impossible to sort like before by clicking on the column name that we want to sort :s.

Any idea to keep a default sort and a custom sort for the user ?

@pcreux

Not really. Please ask the mailing list for support. :)

@keysen

Ok no problem.

Enjoy :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.