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
Accusamus voluptatem vero rerum nemo. jessy_kshlerin@gibson.name 4 2012-08-16
Consequuntur facere et omnis. terrance@satterfield.com 10 2012-08-16
Culpa quibusdam ipsa nostrum maiores ut debitis. billy.considine@orn.info 5 2012-08-16
Debitis suscipit voluptatem nam cupiditate ullam et omnis. althea_kerluke@schmittschinner.uk 7 2012-08-16
Deleniti doloribus quia tempore occaecati quidem. mikel@gutkowski.com 2 2012-08-16
Deserunt accusantium ducimus aspernatur repellendus aut assumenda nihil. delaney_johnston@kreiger.ca 1 2012-08-16
Dolor modi ut impedit omnis aliquam fuga harum amet. nikki@bartellpurdy.com 4 2012-08-16
Eius quia eveniet ullam fugit porro perferendis. sunny@thielgrant.biz 5 2012-08-16
Enim ut optio ullam voluptate odit sint dolores molestiae. earlene.larson@effertzrowe.co.uk 3 2012-08-16
Eos laudantium quibusdam voluptatibus quo voluptatem expedita at quia. adrienne_rolfson@williamson.name 0 2012-08-16
Est esse nostrum ut iure porro. bailee@hellerdouglas.uk 10 2012-08-16
Est temporibus sint natus consequatur aut dolor dolorem. maribel.graham@will.uk 8 2012-08-16
Et cupiditate sed sapiente qui provident. nona_osinski@gulgowski.uk 8 2012-08-16
Et delectus fugit praesentium. urban@lang.info 4 2012-08-16
Eum quis deleniti excepturi vitae. ashly@klockobeahan.ca 0 2012-08-16
Fugiat expedita quis magnam excepturi deleniti velit. cleve@schoen.us 2 2012-08-16
Id numquam rerum voluptatem. isabelle_reilly@stehrmcglynn.uk 6 2012-08-16
In aut et ut. kiley.hettinger@berge.info 4 2012-08-16
In debitis est non. avery_brakus@lindgren.biz 6 2012-08-16
Ipsa pariatur reprehenderit id aut quisquam saepe. hettie_kutch@stehrfay.info 3 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
Laboriosam labore quam ut atque sint suscipit qui. alaina@dietrich.name 3 2012-08-16
Libero in qui odio quis. leonard.zemlak@brakus.us 2 2012-08-16
Minima omnis debitis et ipsam necessitatibus nemo. sofia@cummerata.info 9 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>