-
order by a single column/attribute
-
possibility to add your own callbacks on ordering
-
jruby-rails
-
jquery-ui-rails
-
Gemfile
gem 'u_order', '~> 0.2', :git => 'https://github.com/m0gg/u_order-rails.git'
-
application.js
//= require u_order
-
Identify a table to be ordered,
data-table
is an ordergroup name you may choose yourself, it’s independant of the actual table or collection.<table data-table="posts"> <tr>
-
Ordermodes are controlled by the
order-mode
attribute. Default is +“single”+, +“multi”+ allows to order by more than one attribute, last clicked with highest priority. (since 0.3.a)<table order-mode="multi" data-table="posts">
-
Set the attribute to order with
data-order
, this one would order bytitle
<th data-order="title">Title</th>
-
Ordercycles are controlled by the
order-cycle
attribute. Default is +“asc desc”+, there are 3 implemented cycles,asc
,desc
andnone
. Ifnone
is reached, the ordering on this head is removed.<th order-cycle="desc asc none" data-order="title">Title</th>
-
The last thing is to call the
uorder
method with chosen params on your ActiveRecord relation. Thedata-order
attribute is prefixed with “uorder_”@posts = Post.uorder(params[:uorder_posts])