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
Fugiat veritatis et incidunt odit voluptatum. zackary@crona.co.uk 6 2011-12-11
Vel facere sit quod quis sapiente cupiditate. virgie_hermann@rogahnkerluke.uk 7 2011-12-11
Sed unde aperiam aut quia ut illo. vicente.cassin@hansenfunk.co.uk 1 2011-12-11
Quis itaque fugit qui maxime. tyrese.jacobson@bechtelar.uk 1 2011-12-11
Illo quidem ut adipisci earum ea. sylvan@mclaughlin.info 3 2011-12-11
Est explicabo voluptatum et assumenda distinctio. stewart@doyle.info 1 2011-12-11
Exercitationem ipsam et quae consectetur eos iure. shea_hansen@cremin.uk 7 2011-12-11
Sed sed voluptate tempora possimus. sabrina.feest@berniercummerata.uk 0 2011-12-11
Aperiam molestias nostrum incidunt. polly@pourosstracke.co.uk 4 2011-12-11
Iste omnis sit exercitationem necessitatibus et culpa. ollie@bogan.com 10 2011-12-11
Ut ut sapiente eligendi voluptas fugiat. odell.maggio@becker.co.uk 2 2011-12-11
Iusto asperiores et dolores enim ut qui dicta est. newell@monahankeeling.ca 3 2011-12-11
Vitae autem quis laborum et nemo consequatur. mozelle@crona.info 7 2011-12-11
Tempore vitae qui repudiandae et esse. melany@gerhold.com 0 2011-12-11
Maiores libero voluptas repellat laboriosam eos. marjorie.howell@kuphal.biz 2 2011-12-11
Quo natus illo ullam voluptatem velit amet dicta possimus. margot.jaskolski@hicklegaylord.co.uk 10 2011-12-11
Beatae praesentium aut nihil. marcelino@pfefferrunolfsdottir.name 0 2011-12-11
Veritatis enim quo quia tenetur inventore quas. lillian@walsh.uk 9 2011-12-11
Tempora corporis odit distinctio veritatis cumque. levi@kuhlmankohler.info 6 2011-12-11
Ipsum similique deserunt vero. laury@monahanskiles.co.uk 4 2011-12-11
Perferendis quo necessitatibus est dolorem enim nisi quos. khalil@kreiger.biz 7 2011-12-11
Dolor animi eos alias libero ab aut. keven@ziemann.com 7 2011-12-11
Id et cupiditate veritatis aliquam voluptas dignissimos molestias quasi. kennith@prosacco.name 4 2011-12-11
Ratione eius consequatur consequuntur. jonathan.adams@williamson.biz 10 2011-12-11
A odio eaque esse dolorem in vel incidunt. joanny@homenick.co.uk 7 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>