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
Impedit soluta est eum dignissimos omnis. christine.beer@nolanfritsch.co.uk 10 2011-12-11
Illo quidem ut adipisci earum ea. sylvan@mclaughlin.info 3 2011-12-11
Id et cupiditate veritatis aliquam voluptas dignissimos molestias quasi. kennith@prosacco.name 4 2011-12-11
Fugiat veritatis et incidunt odit voluptatum. zackary@crona.co.uk 6 2011-12-11
Facilis laborum voluptas suscipit asperiores consequatur assumenda. anais.mcclure@johns.us 1 2011-12-11
Facere quam at et. alexander.damore@walter.com 6 2011-12-11
Exercitationem ipsam et quae consectetur eos iure. shea_hansen@cremin.uk 7 2011-12-11
Et non non laborum. brian.hilll@hackett.com 7 2011-12-11
Et molestias minus eligendi fugiat laborum aut non. carmela@von.biz 2 2011-12-11
Est explicabo voluptatum et assumenda distinctio. stewart@doyle.info 1 2011-12-11
Est dolore iste quia maxime laborum. jeramie@howell.biz 8 2011-12-11
Esse non perferendis ut eligendi ea culpa. erica@daniel.co.uk 9 2011-12-11
Eos vero numquam ut. chloe.sipes@bartoletti.info 9 2011-12-11
Eligendi quo quam dicta aut odio sit doloremque ad. heloise.bartell@auer.biz 0 2011-12-11
Earum assumenda quo et non architecto mollitia est iste. benny_romaguera@wisoky.us 7 2011-12-11
Doloremque aliquid laboriosam saepe quia non magnam dolore quaerat. abby_morissette@beier.biz 8 2011-12-11
Dolor animi eos alias libero ab aut. keven@ziemann.com 7 2011-12-11
Distinctio quibusdam eveniet tenetur quaerat. gregory.trantow@kshlerin.com 0 2011-12-11
Cum blanditiis laudantium quos sint. dayana@rohan.biz 0 2011-12-11
Consequatur molestiae dolores et et. esther_reynolds@nitzsche.us 0 2011-12-11
Beatae praesentium aut nihil. marcelino@pfefferrunolfsdottir.name 0 2011-12-11
Autem et aut numquam ut ut consequuntur. celia@will.biz 5 2011-12-11
Aperiam molestias nostrum incidunt. polly@pourosstracke.co.uk 4 2011-12-11
A vero quis expedita maxime dolorum aperiam. hassan@reillymaggio.us 0 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>