# Rail 2.2 Sort multiple Columns in report

**URL:** <https://www.ruby-forum.com/t/rail-2-2-sort-multiple-columns-in-report/163189>\
**Category:** Rails\
**Created:** [March 18, 2009, 5:25am UTC](https://www.ruby-forum.com/t/rail-2-2-sort-multiple-columns-in-report/163189 "2009-03-18T05:25:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_H\_Stewart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e47774/32.png) [@Ian\_H\_Stewart](https://www.ruby-forum.com/u/Ian_H_Stewart)\
**Post date:** [March 18, 2009, 5:25am UTC](https://www.ruby-forum.com/t/rail-2-2-sort-multiple-columns-in-report/163189/1 "2009-03-18T05:25:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Ian\_H\_Stewart](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e47774/32.png) [@Ian\_H\_Stewart](https://www.ruby-forum.com/u/Ian_H_Stewart)\
**Post date:** [March 18, 2009, 7:19am UTC](https://www.ruby-forum.com/t/rail-2-2-sort-multiple-columns-in-report/163189/2 "2009-03-18T07:19:53Z")

</div>

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.
