No commit activity in last 3 years
No release in over 3 years
Reorder index table rows plugin for activeadmin.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

activeadmin-mongoid-reorder

Helper method to add reorder rows functionality to active admin index table view.

Setup

Add gem to Gemfile:

gem activeadmin-mongoid-reorder

Add Monogoid::Reorder to the model declaration you want to be reordarable. This will add reorder_objects class method, _position field and set default sorting order to :_position => :desc - so haviest goes first.

Example:

class Page
  include Mongoid::Document
  include Mongoid::Reorder

  # Fields
  field :title,     :type => String
  field :content,   :type => String
end

To the end of admin registration method of each reordarable model add the following generic helper:

collection_action :reorder, :method => :put do
  render :text => resource_class.reorder_objects(params[:ids])
end

Reorder table type should be specified for index view, here is an example how this should look like:

index :as => :reorder_table do
  column :title
  default_actions
end

And finally enable sorting js functionality. jQuery-ui is included by activeadmin by default, so all you need is to include activeadmin_reoder_table in active_admin.js.coffee:

#= require activeadmin_reorder_table

The End

That's it.