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
Ipsa pariatur reprehenderit id aut quisquam saepe. hettie_kutch@stehrfay.info 3 2012-08-16
Id numquam rerum voluptatem. isabelle_reilly@stehrmcglynn.uk 6 2012-08-16
Accusamus voluptatem vero rerum nemo. jessy_kshlerin@gibson.name 4 2012-08-16
Quo molestias hic labore. joany@lubowitz.uk 1 2012-08-16
In aut et ut. kiley.hettinger@berge.info 4 2012-08-16
Libero in qui odio quis. leonard.zemlak@brakus.us 2 2012-08-16
Provident praesentium eveniet quod neque qui autem sit. lesley@welch.name 5 2012-08-16
Est temporibus sint natus consequatur aut dolor dolorem. maribel.graham@will.uk 8 2012-08-16
Minus sed beatae cumque placeat. marlee@kuhnrobel.com 2 2012-08-16
Ratione quia dolores reprehenderit hic aut optio cumque et. meaghan@hand.name 7 2012-08-16
Ut qui quam quis ea voluptates voluptatibus vel. melody_mitchell@kozey.uk 4 2012-08-16
Deleniti doloribus quia tempore occaecati quidem. mikel@gutkowski.com 2 2012-08-16
Voluptas quam eveniet facilis occaecati. nicholaus.hermiston@roob.name 10 2012-08-16
Dolor modi ut impedit omnis aliquam fuga harum amet. nikki@bartellpurdy.com 4 2012-08-16
Et cupiditate sed sapiente qui provident. nona_osinski@gulgowski.uk 8 2012-08-16
Numquam aut in officia dolores quod omnis omnis. raphael@kreigerwilkinson.com 5 2012-08-16
Sequi facere est voluptates error. rowena@jaskolskischmidt.name 6 2012-08-16
Iste quas et ex laborum nihil. shanel_hickle@metz.com 5 2012-08-16
Sapiente doloribus officia nihil. shanon@anderson.ca 7 2012-08-16
Minima omnis debitis et ipsam necessitatibus nemo. sofia@cummerata.info 9 2012-08-16
Eius quia eveniet ullam fugit porro perferendis. sunny@thielgrant.biz 5 2012-08-16
Consequuntur facere et omnis. terrance@satterfield.com 10 2012-08-16
Et delectus fugit praesentium. urban@lang.info 4 2012-08-16
Sunt voluptas excepturi pariatur est et necessitatibus quae ipsam. vince.mosciski@predovic.biz 7 2012-08-16
Optio pariatur placeat accusantium qui in saepe. wendell@pricemacejkovic.uk 1 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>