<commit_before># MightyGrid [![Gem Version](http://img.shields.io/gem/v/mighty_grid.svg)](http://badge.fury.io/rb/mighty_grid) [![Build Status](https://travis-ci.org/jurrick/mighty_grid.svg?branch=master)](https://travis-ci.org/jurrick/mighty_grid) [![Code Climate](https://codeclimate.com/github/jurrick/mighty_grid.png)](https://codeclimate.com/github/jurrick/mighty_grid) [![Inline docs](http://inch-ci.org/github/jurrick/mighty_grid.png)](http://inch-ci.org/github/jurrick/mighty_grid)

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:

    ```ruby
    class ProductsGrid < MightyGrid::Base
      scope { Product }
    end
    ```

2. Initialize the grid in a controller

    ```ruby
    def index
      @products_grid = ProductsGrid.new(params)
    end
    ```

3. Show created grid

    ```ruby
    <%= 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:

```ruby
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 <tt>MightyGrid.setup</tt> 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.

## 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<commit_msg>Write section about support Thinking Sphinx<commit_after># MightyGrid [![Gem Version](http://img.shields.io/gem/v/mighty_grid.svg)](http://badge.fury.io/rb/mighty_grid) [![Build Status](https://travis-ci.org/jurrick/mighty_grid.svg?branch=master)](https://travis-ci.org/jurrick/mighty_grid) [![Code Climate](https://codeclimate.com/github/jurrick/mighty_grid.png)](https://codeclimate.com/github/jurrick/mighty_grid) [![Inline docs](http://inch-ci.org/github/jurrick/mighty_grid.png)](http://inch-ci.org/github/jurrick/mighty_grid)

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:

    ```ruby
    class ProductsGrid < MightyGrid::Base
      scope { Product }
    end
    ```

2. Initialize the grid in a controller

    ```ruby
    def index
      @products_grid = ProductsGrid.new(params)
    end
    ```

3. Show created grid

    ```ruby
    <%= 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:

```ruby
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 <tt>MightyGrid.setup</tt> 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

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

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

## 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
{'fraction_non_alphanumeric': 0.11352621530327507, 'fraction_numerical': 0.00587457776472316, 'mean_word_length': 3.4163424124513617, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 17, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5053294', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2034, 'n_words': 661}