All Projects → itmammoth → Rails_sortable

itmammoth / Rails_sortable

Licence: mit
Easy drag & drop sorting with persisting the arranged order for rails

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Rails sortable

Ordinare
Ordinare sorts gems in your Gemfile alphabetically
Stars: ✭ 153 (+20.47%)
Mutual labels:  sort, rails, gem
Tabler Rubygem
Rubygem for https://tabler.github.io
Stars: ✭ 77 (-39.37%)
Mutual labels:  rails, gem
Render async
render_async lets you include pages asynchronously with AJAX
Stars: ✭ 974 (+666.93%)
Mutual labels:  rails, gem
Validates formatting of
Common Rails validations wrapped in a gem.
Stars: ✭ 91 (-28.35%)
Mutual labels:  rails, gem
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+625.2%)
Mutual labels:  rails, gem
Adminpanel
This gem has the goal to act as the administration panel for your resources, so you can focus only on the public part of your app
Stars: ✭ 7 (-94.49%)
Mutual labels:  rails, gem
Pager Api
Easy API pagination for Rails
Stars: ✭ 86 (-32.28%)
Mutual labels:  rails, gem
Yt
The reliable YouTube API Ruby client
Stars: ✭ 674 (+430.71%)
Mutual labels:  rails, gem
Muuri
Infinite responsive, sortable, filterable and draggable layouts
Stars: ✭ 9,797 (+7614.17%)
Mutual labels:  sort, drag-and-drop
Instagram api gem
A Ruby wrapper for the Instagram API
Stars: ✭ 100 (-21.26%)
Mutual labels:  rails, gem
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (-21.26%)
Mutual labels:  rails, gem
Bh
Bootstrap Helpers for Ruby
Stars: ✭ 834 (+556.69%)
Mutual labels:  rails, gem
Octicons
A scalable set of icons handcrafted with <3 by GitHub
Stars: ✭ 7,039 (+5442.52%)
Mutual labels:  rails, gem
Administrate Field Belongs to search
Plugin that adds search capabilities to belongs_to associations for Administrate
Stars: ✭ 29 (-77.17%)
Mutual labels:  rails, gem
Materialize Sass
Materializecss rubygem for Rails Asset Pipeline / Sprockets
Stars: ✭ 785 (+518.11%)
Mutual labels:  rails, gem
Bhf
Rails-Engine-Gem that offers an admin interface for trusted user
Stars: ✭ 81 (-36.22%)
Mutual labels:  rails, gem
Counter culture
Turbo-charged counter caches for your Rails app.
Stars: ✭ 1,397 (+1000%)
Mutual labels:  rails, gem
Motion
Reactive frontend UI components for Rails in pure Ruby
Stars: ✭ 498 (+292.13%)
Mutual labels:  rails, gem
Sortable
Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
Stars: ✭ 23,641 (+18514.96%)
Mutual labels:  sort, drag-and-drop
Lol dba
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
Stars: ✭ 1,363 (+973.23%)
Mutual labels:  rails, gem

RailsSortable

Build Status

RailsSortable is a simple Rails gem that allows you to create a listing view with drag & drop sorting. The arranged order will be persisted in the table without any pain.

RailsSortable

Setup

Add the following to your Gemfile then run bundle to install them.

gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'rails_sortable'

And then add the following to the asset pipeline in the application.js:

//= require jquery
//= require jquery_ujs
//= require jquery-ui/widgets/sortable
//= require rails_sortable

Usage

RailsSortable requires a specific column on the ActiveRecord Model for its implementation.

For instance, the following migration indicates the case that you are attempting to make Item model sortable.

class CreateItems < ActiveRecord::Migration[5.1]
  def change
    create_table :items do |t|
      t.string :title
      t.integer :sort  # for RailsSortable

      t.timestamps
    end
  end
end

and Item model as

class Item < ApplicationRecord
  include RailsSortable::Model
  set_sortable :sort  # Indicate a sort column
  # If you do NOT want timestamps to be updated on sorting, use the following option.
  # set_sortable :sort, without_updating_timestamps: true
end

and ItemsController as

class ItemsController < ApplicationController
  def index
    @items = Item.order(:sort).all
  end
end

and the listing view (typically - index.html.erb) as

...
<table>
  <tbody class="sortable">  <!-- sortable target -->
    <% @items.each_with_sortable_id do |item, sortable_id| %>
      <tr id="<%= sortable_id %>">  <!-- Needs id tag on sorting elements -->
        <td><%= item.title %></td>
        <td><%= item.sort %></td>
        <td><%= link_to 'Show', item %></td>
        <td><%= link_to 'Edit', edit_item_path(item) %></td>
        <td><%= link_to 'Destroy', item, method: :delete, data: { confirm: 'Are you sure?' } %></td>
      </tr>
    <% end %>
  </tbody>
</table>

<!-- or just invoke model#sortable_id to get the id for sotable -->
...
<% @items.each do |item| %>
  <tr id="<%= item.sortable_id %>">
...

finally, apply sortable with Javascript.

$(function() {
  $('.sortable').railsSortable();
});

More

Please have a look at Use [email protected] for further information.

Javascript options

jQuery plugin railsSortable is just a wrapper of jquery.ui.sortable. therefore it accepts all of sortable options.

see the http://api.jqueryui.com/sortable/ to get the details.

Contribution

Fork it, then install required gems like below.

$ bundle install

Please give me a PR freely.

Testing

# Test with a dummy application
$ spec/dummy/bin/rails db:migrate
$ spec/dummy/bin/rails s
# Insert test data
$ spec/dummy/bin/rails db:seed

# Run rspecs
$ bundle exec rspec

Licence

MIT Licence.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].