Coder Social home page Coder Social logo

ujs_sort_helper's Introduction

=UnobtrusiveSortHelper


This is a plugin version of Stuart Rackham's most excellent SortHelper helper. The link_to_remote ajax calls have been removed in favor of unobtrusive javascript using lowpro.js.

=== Features

- 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 will_paginate plugin

=== Usage

====Controller:

   def list
     sort_init 'last_name'
     sort_update
     @items = Contact.find_all nil, sort_clause
   end
   
====Controller (using will_paginate)

   def list
     sort_init 'last_name'
     sort_update

     options = {:page => params[:page], :include => :addresses, :order => sort_clause }

     @contacts = Contact.paginate(options)
   end
   
====Layout (app/views/layouts/application.html.erb):

  <%= stylesheet_link_tag "ujs_sort_helper"%> 
styles for nifty sort arrow images

  <%= javascript_include_tag :defaults%> 
as long as prototype.js is included before lowpro and ujs_sort_helper

If you're not using jQuery, reference Dan Webb's lowpro and the Prototype version
of the ujs_sort_helper:

  <%= javascript_include_tag "lowpro"%> 
you SHOULD already have this ;-)

  <%= javascript_include_tag "ujs_sort_helper", :plugin => "ujs_sort_helper"%> 

If you're using jQuery, simply include the jQuery version (assuming you already
have jQuery and livequery installed)

<%= javascript_include_tag "ujs_sort_helper.jquery.js", :plugin => "ujs_sort_helper"%> 


====View (table header in index.rhtml):
 
   <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>

- The ascending and descending sort icon images are sort_asc.png and sort_desc.png and reside in the application's images directory.
- Introduces instance variables: @sort_name, @sort_default.
- Introduces params :sort_key and :sort_order.



Copyright (c) 2005 Stuart Rackham, (c) 2008 Wynn Netherland released under the MIT license

ujs_sort_helper's People

Contributors

pengwynn avatar likebees avatar

Watchers

James Cloos avatar Zach avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.