Sorted::Activerecord
These helpers will let you sort large datasets over many pages (using will_paginate or kaminari) without losing state.
Installation
Add this line to your application's Gemfile:
gem 'sorted-activerecord'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sorted-activerecord
Usage
Using the sorted
method with the optional default order argument:
@users = User.sorted(params[:sort], "email ASC").page(params[:page])
A resorted
method is also available and works the same way as the reorder
method in Rails.
It forces the order to be the one passed in:
@users = User.order(:id).sorted(nil, 'name DESC').resorted(params[:sort], 'email ASC')
Contributing
- Fork it ( https://github.com/[my-github-username]/sorted-activerecord/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request