Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic_grid

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic_grid

  • 0.12.6
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

MagicGrid

© 2011-2013 Ryan Graham, Dennis Taylor

Gem Version 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.

:title

Sets a text string to include in the top of the grid's thead to display as a title for the grid.

and more...

There's a.. ahem slight lack of documentation at the moment. Pull requests welcome?

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.

FAQs

Package last updated on 22 Jul 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc