Forum: Ruby on Rails Rail 2.2 Sort multiple Columns in report

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ian H Stewart (Guest)
on 2009-03-18 06:25
(Received via mailing list)
My end user would like a report on a single page that he can select
the header field and sort by that.

First all the data is laid out in a table.
Then each row is a different user record.


Name    State    Zip    Points


Any tips on how I could allow the user to click an ASC or DESC
arrow next to each Column to sort the page?

I am only working with about 75 user records now, but understand
it may grow in which case I will be using the wil_paginate plugin so
please
keep that in mind for the advice.

I was looking at sortable_column_headers, but told it is not supported
in
rails 2.2.

Thanks in advance.

Ian
Robert W. (Guest)
on 2009-03-18 08:19
Ian H Stewart wrote:
> My end user would like a report on a single page that he can select
> the header field and sort by that.

Wouldn't you just need to construct an "order by" clause and use that
when you find the records?

@users = User.find(:all, :order => "state, points DESC")

I might even suggest updating the list through AJAX, but that's not
required if you don't mind a page refresh when selecting sorting
controls. You'll, of course, need to keep track of the storing state
between requests, which you could do using the session, or any number of
others common techniques.
This topic is locked and can not be replied to.