项目作者: jurrick

项目描述 :
Simple and flexible grid solution for Ruby On Rails
高级语言: Ruby
项目地址: git://github.com/jurrick/mighty_grid.git
创建时间: 2014-04-13T20:20:22Z
项目社区:https://github.com/jurrick/mighty_grid

开源协议:MIT License

下载


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:

  1. gem 'mighty_grid'

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

  1. $ 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:

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

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

    1. <%= grid @products_grid do |g| %>
    2. <% - g.column :id %>
    3. <% - g.column :name %>
    4. <% - g.column :description %>
    5. <% end %>

Usage

Filters

A simple example of the use of filters:

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

General configuration options

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

  1. per_page # 15 by default
  2. order_direction # 'asc' by default
  3. order_type # 'single' by default
  4. order_asc # '↑' by default
  5. order_desc # '↓' by default
  6. order_asc_link_class # '' by default
  7. order_desc_link_class # '' by default
  8. order_active_link_class # 'mg-order-active' by default
  9. order_wrapper_class # '' by default
  10. grid_name # 'grid' by default
  11. table_class # '' by default
  12. header_tr_class # '' by default
  13. 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

  1. class ProductsGrid < MightyGrid::Base
  2. scope { Product }
  3. use_thinking_sphinx true
  4. sphinx_options indices: ['product_public_core']
  5. search :query
  6. 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:

  1. $ 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