Menu

jQuery UI

Sheba Liveoak

Put the following in your application controller to generate jQuery UI links:

class ApplicationController < ActionController::Base
  def link_to_sorted(name, order) 
    dup_params = (request.get? && !params.nil?) ? params.dup : nil
    sorter     = ActionView::Base::SortedViewHelper.new(order, dup_params)
    css_class  = case sorter.css    
                 when "sorted asc"               
                   "ui-icon ui-icon-triangle-1-n"  
                 when "sorted desc"              
                   "ui-icon ui-icon-triangle-1-s"  
                 when "sorted"
                   "ui-icon ui-icon-carat-2-n-s"   
                 end
    link_to(content_tag(:span, nil, {:class => css_class}) + name.to_s, sorter.params)
  end
end

Then in your table create table headers with the method:

<th class="ui-state-default"><%= link_to_sorted 'Name', :name %></th>

Related

Wiki: Home

MongoDB Logo MongoDB