by Stuart Rackham  
"Download":http://www.methods.co.nz/misc/sort_helper.rb    
"Screenshot":http://www.methods.co.nz/misc/sort_helper_screenshot.png

Helpers to sort tables using clickable column headers.

* Consecutive clicks toggle the column's sort order.
* Sort state is maintained by a session hash entry.
* Icon image identifies sort column and state.
* Typically used in conjunction with the Pagination module.

NOTE: Requires Rails 0.11.0

It's use is straight-forward:

Controller:

<pre><code>   helper :sort
   include SortHelper

   def list
     sort_init 'last_name'
     sort_update
     @items = Contact.find(:all, :order => sort_clause)
   end</code></pre>

View (table header in list.rhtml):

<pre><code>   <thead>
     <tr>
       <%= sort_header_tag('id', :title => 'Sort by contact ID') %>
       <%= sort_header_tag('last_name', :caption => 'Name') %>
       <%= sort_header_tag('phone') %>
       <%= sort_header_tag('address', :width => 200) %>
     </tr>
   </thead></code></pre>

category:Helper
