Sortable List plugin
Plugin details
Documentation
ruby script/plugin install svn://rubyforge.org/var/svn/sortable-list/trunk
To use simply put this in your table header
<%=s :first_name%>
This will create markup that looks like the following:
First Name params[:sort]
If the current field is the field being sorted then it will do the opposite direction. So if the user clicked the link for the past request then the same code will now generate
href="?sort=first_name%20DESC">First Name
This allows users to reverse the order simply by clicking the link again. In addition sortable_header method takes a option hash as the second argument with the following valid options:
label: If humanize is not guessing your field name correctly you can use this to give an explicit label.
descend: Set to true if you want this column to initially be decending. Date columns are often used in this way.
default: Set to true if this column is the default sort column. This means that if the :sort param has no value this column assumes it is sorting the data. You should specify one column with default => true
asc_img: The name of an image to show beside the column if we are sorting in an assending order (this should probably be a down arrow).
desc_img: The name of an image to show beside the column if we are sorting in a descending order (this should probably be a up arrow).
Since you most likely do not want to specify a asc_img and desc_img on every execution of the sortable_header method you can also define the following constants so the images are automatically included without explicit specification
* SORTABLE_COLUMN_ASC
* SORTABLE_COLUMN_DESC
NOTE: This method is aliased as s for easy programming much like the h method which escapes html_escape
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | Back in time (1 older version) | Last edited by: scott, 4 months ago

