As I see this is simple.
1) Attach a hyperlink to your table column headers (html) passing the column name as the parameter. (list.rhtml) <table>
<th><a href="?sort_by=name">Name</a></th> .. .. </table>
2) In your controller add the following to the method for listing your records (list action)
def list sort_by = params[:sort_by] sort_by ||= " name" # for default sort @users = User.find(:user_search_query, ::order => sort_by) # you will need the :include option here to join the roles table
See how simple is that.
Hi, It is working fine.
But in my case i wanted to display the items in sorted order from different tables.
is there any way to get the values sorted from objects(not from the tables)?
Ex: I have a users and roles table. @user_roles = some query result (values from both the tables)
any way to perform sort operation on @user_roles instead of User and Role table?
Please let us know, any one knew this.
As i know, guys from ELC did plugin for that: http://www.elctech.com/2007/5/8/sortable-column-headers
Here is my problem.
I have user table with fields name, role and login_time.
Same way i am displaying those 3 fields in a