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
Eum quis deleniti excepturi vitae. ashly@klockobeahan.ca 0 2012-08-16
Est temporibus sint natus consequatur aut dolor dolorem. maribel.graham@will.uk 8 2012-08-16
Deserunt accusantium ducimus aspernatur repellendus aut assumenda nihil. delaney_johnston@kreiger.ca 1 2012-08-16
Enim ut optio ullam voluptate odit sint dolores molestiae. earlene.larson@effertzrowe.co.uk 3 2012-08-16
Culpa quibusdam ipsa nostrum maiores ut debitis. billy.considine@orn.info 5 2012-08-16
Quo recusandae sed voluptate impedit quia qui. clark.roob@rogahnrath.us 10 2012-08-16
In aut et ut. kiley.hettinger@berge.info 4 2012-08-16
Eos laudantium quibusdam voluptatibus quo voluptatem expedita at quia. adrienne_rolfson@williamson.name 0 2012-08-16
Iste quas et ex laborum nihil. shanel_hickle@metz.com 5 2012-08-16
Laboriosam et cupiditate et est optio sit incidunt. deanna@kovacekcorwin.biz 2 2012-08-16
Minus sed beatae cumque placeat. marlee@kuhnrobel.com 2 2012-08-16
Perspiciatis inventore dicta provident sunt. anjali_morissette@erdman.ca 1 2012-08-16
Sequi facere est voluptates error. rowena@jaskolskischmidt.name 6 2012-08-16
Laboriosam labore quam ut atque sint suscipit qui. alaina@dietrich.name 3 2012-08-16
Nesciunt officia alias est quod eos eligendi. florine.ziemann@toy.com 8 2012-08-16
Ipsa pariatur reprehenderit id aut quisquam saepe. hettie_kutch@stehrfay.info 3 2012-08-16
Voluptas quam eveniet facilis occaecati. nicholaus.hermiston@roob.name 10 2012-08-16
Minima omnis debitis et ipsam necessitatibus nemo. sofia@cummerata.info 9 2012-08-16
Non nemo et dolorem aperiam inventore quidem maxime enim. berta.boehm@hudson.com 9 2012-08-16
Quia quibusdam vel natus alias architecto. estrella@bauchmonahan.biz 8 2012-08-16
Perspiciatis esse molestiae non quia dolorem omnis. else_greenfelder@bayerbradtke.info 2 2012-08-16
Temporibus voluptatum quaerat et dolore autem consequatur. gianni@nicolasparisian.name 0 2012-08-16
Quo molestias hic labore. joany@lubowitz.uk 1 2012-08-16
Provident praesentium eveniet quod neque qui autem sit. lesley@welch.name 5 2012-08-16
Nobis laudantium iste aut minima. elisha@connellychamplin.co.uk 7 2012-08-16

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>