This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
Wynn Netherland (author)
Mon Apr 21 09:19:03 -0700 2008
ujs_sort_helper / README
| dc93fdbf » | Wynn Netherland | 2008-04-21 | 1 | =UnobtrusiveSortHelper | |
| 2 | |||||
| 3 | |||||
| 4 | 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. | ||||
| 5 | |||||
| 6 | === Features | ||||
| 7 | |||||
| 8 | - Consecutive clicks toggle the column's sort order. | ||||
| 9 | - Sort state is maintained by a session hash entry. | ||||
| 10 | - Icon image identifies sort column and state. | ||||
| 11 | - Typically used in conjunction with will_paginate plugin | ||||
| 12 | |||||
| 13 | === Usage | ||||
| 14 | |||||
| 15 | ====Controller: | ||||
| 16 | |||||
| 17 | def list | ||||
| 18 | sort_init 'last_name' | ||||
| 19 | sort_update | ||||
| 20 | @items = Contact.find_all nil, sort_clause | ||||
| 21 | end | ||||
| 22 | |||||
| 23 | ====Controller (using will_paginate) | ||||
| 24 | |||||
| 25 | def list | ||||
| 26 | sort_init 'last_name' | ||||
| 27 | sort_update | ||||
| 28 | |||||
| 29 | options = {:page => params[:page], :include => :addresses, :order => sort_clause | ||||
| 30 | |||||
| 31 | @contacts = Contact.paginate(options) | ||||
| 32 | end | ||||
| 33 | |||||
| 34 | ====Layout (app/views/layouts/application.html.erb): | ||||
| 35 | |||||
| 36 | <%= stylesheet_link_tag "ujs_sort_helper"%> | ||||
| 37 | styles for nifty sort arrow images | ||||
| 38 | |||||
| 39 | <%= javascript_include_tag :defaults%> | ||||
| 40 | as long as prototype.js is included before lowpro and ujs_sort_helper | ||||
| 41 | |||||
| 43d96868 » | Wynn Netherland | 2008-04-21 | 42 | If you're not using jQuery, reference Dan Webb's lowpro and the Prototype version | |
| 43 | of the ujs_sort_helper: | ||||
| 44 | |||||
| dc93fdbf » | Wynn Netherland | 2008-04-21 | 45 | <%= javascript_include_tag "lowpro"%> | |
| 46 | you SHOULD already have this ;-) | ||||
| 47 | |||||
| a06e09ed » | Wynn Netherland | 2008-04-21 | 48 | <%= javascript_include_tag "ujs_sort_helper", :plugin => "ujs_sort_helper"%> | |
| 43d96868 » | Wynn Netherland | 2008-04-21 | 49 | ||
| 50 | If you're using jQuery, simply include the jQuery version (assuming you already | ||||
| 51 | have jQuery and livequery installed) | ||||
| 52 | |||||
| a06e09ed » | Wynn Netherland | 2008-04-21 | 53 | <%= javascript_include_tag "ujs_sort_helper.jquery.js", :plugin => "ujs_sort_helper"%> | |
| 43d96868 » | Wynn Netherland | 2008-04-21 | 54 | ||
| 55 | |||||
| dc93fdbf » | Wynn Netherland | 2008-04-21 | 56 | ====View (table header in index.rhtml): | |
| 57 | |||||
| 58 | <thead> | ||||
| 59 | <tr> | ||||
| 60 | <%= sort_header_tag('id', :title => 'Sort by contact ID') %> | ||||
| 61 | <%= sort_header_tag('last_name', :caption => 'Name') %> | ||||
| 62 | <%= sort_header_tag('phone') %> | ||||
| 63 | <%= sort_header_tag('address', :width => 200) %> | ||||
| 64 | </tr> | ||||
| 65 | </thead> | ||||
| 66 | |||||
| 67 | - The ascending and descending sort icon images are sort_asc.png and sort_desc.png and reside in the application's images directory. | ||||
| 68 | - Introduces instance variables: @sort_name, @sort_default. | ||||
| 69 | - Introduces params :sort_key and :sort_order. | ||||
| 70 | |||||
| 71 | |||||
| 72 | |||||
| 73 | Copyright (c) 2005 Stuart Rackham, (c) 2008 Wynn Netherland released under the MIT license | ||||







