Giter VIP home page Giter VIP logo

magic_grid's Introduction

MagicGrid

© 2011-2013 Ryan Graham, Dennis Taylor

Build Status Code Climate

Easy collection display grid with column sorting and pagination.

MagicGrid Live Demo (it's not very pretty. Help?)

Displays a collection (ActiveRelation or Array) wrapped in an html table with server side column sorting, filtering hooks, and search bar. Large collections can be paginated with either the will_paginate gem or kaminari gem if you use them, or a naive Enumerable based paginator (without pager links) if neither is present.

Tables are styled using Themeroller compatible classes, which also don't look too bad with Bootstrap.

Basic Usage

In your Gemfile:

gem 'magic_grid'

In your controller:

@posts = Post.where(:published => true)

In your view:

<%= magic_grid(@posts, [:title, :author]) %>

What you'll get is an table with 2 sortable columns. You'll also get pagination if you have eitehr Keminari or WillPaginate loaded.

You can also do your own row rendering by passing a block:

<%= magic_grid(@posts, [:title, :author, "Actions"]) do |post| %>
  <tr>
    <td><%= link_to(post.title, post) %></td>
    <td><%= link_to(post.author, post.author) %></td>
    <td>
      <%= link_to("Edit", edit_post_path(post)) %> |
      <%= link_to("Delete", post, method: :delete,
                  data: {confirm: "Are you sure?"}) %>
    </td>
  </tr>
<% end %>

Advanced Options

There are a bunch of extra options that can be passed to the magic_grid helper:

:searchable

An array of columns to try to generate a search query for. Providing this list tells magic_grid to render a search box in the header of the html table it generates. Make sure to include magic_grid.js in your view or application wide via your application.js or search won't work.

:per_page

Sets the number of rows per page in the paginator.

Development

Testing was originally done UnitTest style, with some tarantula to force a bunch of random page renderings. I've since added some RSpec goodness.

To run all the tests, just run rake.

License

Distributed under the MIT license. See MIT-LICENSE for detail.

magic_grid's People

Contributors

fimmtiu avatar rmg avatar

Watchers

 avatar  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.