#29 ✓resolved
wrecko

Custom Conditions & Options Break Sorting

Reported by wrecko | November 20th, 2008 @ 02:20 PM

Upon setting additional conditions or options, I notice that sorting does not work. For example:

    @search = MyModel.new_search(params[:search])
    @search.order_by = [:my_date]
@search.order_as = "DESC"

If I have a table display with a:

remote_order_by_link :my_date

That link will no longer sort by :my_date - I would think that the order_by_link would override the options I've set elsewhere.

I'd like to be able to have the data output with a particular sort order by default, and then sort the columns various ways after it's been displayed. Is there a way to accomplish this?

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson November 20th, 2008 @ 02:23 PM

    • State changed from “new” to “resolved”

    Yep, what you are doing is forcing the order by to be :my_date. What you need to do is this:

    @search = MyModel.new_search(params[:search])
    @search.order_by ||= :my_date
    @search.order_as ||= "DESC"
    

    Let me know if you have any issues. That's how I do it in my own apps.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Tags

Pages