0.0
No commit activity in last 3 years
No release in over 3 years
Simple and flexible grid for Rails
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.5
>= 0
~> 2.14.2

Runtime

~> 0.15
 Project Readme

MightyGrid Gem Version Build Status Code Climate Inline docs

MightyGrid is very simple and flexible grid solution for Ruby On Rails.

Features

  • Ruby 2.x support
  • Rails 4.x support
  • Easy building grids
  • Flexible filtering
  • Simple sorting

Installation

Add this line to your application's Gemfile:

gem 'mighty_grid'

Then run the following generator command in order to generate files for gem customization:

$ rails g mighty_grid:install

After generation you will see the following files:

  • config/initializers/mighty_grid.rb
  • config/locales/mighty_grid.en.yml

Quick Start

  1. Creating grid

    Any grid can be created in a folder app/grids for example as follows:

    class ProductsGrid < MightyGrid::Base
      scope { Product }
    end
  2. Initialize the grid in a controller

    def index
      @products_grid = ProductsGrid.new(params)
    end
  3. Show created grid

    <%= grid @products_grid do |g| %>
      <% - g.column :id %>
      <% - g.column :name %>
      <% - g.column :description %>
    <% end %>

Usage

Filters

A simple example of the use of filters:

class ProductsGrid < MightyGrid::Base
  scope { Product }
  
  filter :name
  filter :status, :enum, collection: [['active', 'Active'], ['inactive', 'Inactive']]
  filter :author, :string, attribute: :name, model: User
end

General configuration options

You can configure the following default values by overriding these values using MightyGrid.setup method.

per_page                # 15 by default
order_direction         # 'asc' by default
order_type              # 'single' by default
order_asc               # '&uarr;' by default
order_desc              # '&darr;' by default
order_asc_link_class    # '' by default
order_desc_link_class   # '' by default
order_active_link_class # 'mg-order-active' by default
order_wrapper_class     # '' by default
grid_name               # 'grid' by default
table_class             # '' by default
header_tr_class         # '' by default
pagination_theme        # 'mighty_grid' by default

There's a handy generator that generates the default configuration file into config/initializers directory.

Thinking Sphinx Support

Example

class ProductsGrid < MightyGrid::Base
  scope { Product }
  
  use_thinking_sphinx true
  
  sphinx_options indices: ['product_public_core']
  
  search :query
end

Scope should contain only the model class (not relation). You can have only one search field.

Note: Currently, filtering is not supported for the search.

Running tests

To run the tests you need specify database and Rails version.

  • List of available Rails versions: 4.0, 4.1, 4.2.
  • List of DB: sqlite, postgresql, mysql.

Example run:

$ DB=postgresql appraisal rails_41 rake spec cucumber

Contributing

  1. Fork it ( http://github.com/jurrick/mighty_grid/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request