Gem source code Demo source code
Author: Bogdan Gusiev

User Grid (basic) Time Entry Grid (advanced) Document Grid (Mongoid)

Documents Grid

Total: 150
Title Author Rating Created at
Non ea aliquam fuga ex expedita ad. aracely@cristnolan.ca 10 2011-12-11
Ipsa non rem necessitatibus fuga. abner_ziemann@heaney.com 10 2011-12-11
Quis in quasi ducimus consequatur est architecto sit dolorem. herminio@lubowitz.ca 10 2011-12-11
Iste omnis sit exercitationem necessitatibus et culpa. ollie@bogan.com 10 2011-12-11
Impedit soluta est eum dignissimos omnis. christine.beer@nolanfritsch.co.uk 10 2011-12-11
Quo natus illo ullam voluptatem velit amet dicta possimus. margot.jaskolski@hicklegaylord.co.uk 10 2011-12-11
Ratione eius consequatur consequuntur. jonathan.adams@williamson.biz 10 2011-12-11
Eos vero numquam ut. chloe.sipes@bartoletti.info 9 2011-12-11
Veritatis enim quo quia tenetur inventore quas. lillian@walsh.uk 9 2011-12-11
Esse non perferendis ut eligendi ea culpa. erica@daniel.co.uk 9 2011-12-11
Omnis accusantium quod voluptatem illum quisquam aut. alison_morissette@wintheiser.uk 9 2011-12-11
Doloremque aliquid laboriosam saepe quia non magnam dolore quaerat. abby_morissette@beier.biz 8 2011-12-11
Est dolore iste quia maxime laborum. jeramie@howell.biz 8 2011-12-11
Exercitationem ipsam et quae consectetur eos iure. shea_hansen@cremin.uk 7 2011-12-11
Dolor animi eos alias libero ab aut. keven@ziemann.com 7 2011-12-11
Et non non laborum. brian.hilll@hackett.com 7 2011-12-11
Voluptatem quae possimus laborum cumque ratione dolor illo. hadley@emmerichkoepp.us 7 2011-12-11
A odio eaque esse dolorem in vel incidunt. joanny@homenick.co.uk 7 2011-12-11
Vel facere sit quod quis sapiente cupiditate. virgie_hermann@rogahnkerluke.uk 7 2011-12-11
Perferendis quo necessitatibus est dolorem enim nisi quos. khalil@kreiger.biz 7 2011-12-11
Vitae autem quis laborum et nemo consequatur. mozelle@crona.info 7 2011-12-11
Earum assumenda quo et non architecto mollitia est iste. benny_romaguera@wisoky.us 7 2011-12-11
Tempora corporis odit distinctio veritatis cumque. levi@kuhlmankohler.info 6 2011-12-11
Fugiat veritatis et incidunt odit voluptatum. zackary@crona.co.uk 6 2011-12-11
Facere quam at et. alexander.damore@walter.com 6 2011-12-11

Grid:

class DocumentsGrid

  include Datagrid

  scope do
    Document.desc(:created_at)
  end

  filter :rating, :enum, :select => 0..10
  filter :title, :header => "Title (contains)" do |value|
    where(:title => /#{Regexp.escape(value)}/i)
  end
  filter :author, :header => "Author (regexp)" do |value|
    begin
      where(:author => Regexp.compile(value))
    rescue RegexpError
      where
    end
  end

  filter :condition, :dynamic, :header => "Dynamic condition"
  column :title 
  column :author 
  column :rating 
  column :created_at do
    self.created_at.to_date
  end

end

Controller:

class DocumentsController < ApplicationController

  def index
    @documents_grid = DocumentsGrid.new(params[:documents_grid]) do |scope|
      scope.page(params[:page])
    end
  end
end

View:


<h3>Documents Grid</h3>

<div class="left">
  <%= datagrid_form_for @documents_grid, url: documents_path %>

  <div class='total'>Total: <%= @documents_grid.assets.count %></div>
  <%= datagrid_table(@documents_grid) %>
  <%= paginate @documents_grid.assets %>
</div>

<div class="right">
  <%= render :partial => "shared/source", :object => @documents_grid %>
</div>