Giter Site home page Giter Site logo

opensourcecannabis / activeadmin_sortable_table Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bolshakov/activeadmin_sortable_table

0.0 1.0 0.0 141 KB

Drag and drop sort interface for ActiveAdmin tables

License: MIT License

Ruby 68.93% JavaScript 21.00% CSS 1.49% HTML 7.60% SCSS 0.97%

activeadmin_sortable_table's Introduction

Build Status Test Coverage Code Climate Gem Version

Active Admin Sortable Table

This gem extends ActiveAdmin so that your index page's table rows can be orderable via a drag-and-drop interface.

Improvements over the @neo version

  1. Test coverage
  2. Configurable labels for handler
  3. Move to top button allows to push any item from any page to the top of the list
  4. Sorting works on all pages ( not only on the first one)

Prerequisites

This extension assumes that you're using acts_as_list on any model you want to be sortable.

class Page < ActiveRecord::Base
  acts_as_list
end

Usage

Add it to your Gemfile

gem "activeadmin_sortable_table"

Include the JavaScript in active_admin.js.coffee

#= require activeadmin_sortable_table

Include the Stylesheet in active_admin.css.scss

@import "activeadmin_sortable_table"

Configure your ActiveAdmin Resource

ActiveAdmin.register Page do
  include ActiveAdmin::SortableTable # creates the controller action which handles the sorting
  config.sort_order = 'position_asc' # assumes you are using 'position' for your acts_as_list column

  index do
    handle_column 
  end

  show do |c|
    attributes_table do
      row :id
      row :name
    end

    panel 'Contents' do
      table_for c.collection_memberships do
        handle_column
        column :position
        column :collectable
      end
    end
  end
end

Configure handler

You can override handler column symbol using handle_column options:

You can configure sort_url using handle column options by providing static value, symbolized instance method name, or blocks.

handle_column sort_url: ->(category) { compute_url_for_category(category) }  
handle_column sort_url: '/admin/categories/1/sort'
handle_column sort_url: :sort_category  

The same options available for move_to_top_url:

handle_column move_to_top_url: '/admin/categories/1/move_to_top

It's also possible to override handle lables:

handle_column sort_handle: '&#9776;'.html_safe
handle_column move_to_top_handle: 'Move to top'

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Prepare tests database (bundle exec rake dummy:prepare)
  4. Make your changes and runs specs (bundle exec rspec)
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create Pull Request

activeadmin_sortable_table's People

Contributors

bolshakov avatar adamlogic avatar jcgertig avatar etozzato avatar faucct avatar bharat311 avatar kdelchev avatar anark avatar nickurban avatar schuetzm avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.