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
Rerum accusantium rerum non vero. shemar_gislason@kohlergutkowski.us 1 2012-08-16
Rem ut dignissimos accusantium omnis id atque dolorem quo. blair.corkery@kshlerin.co.uk 2 2012-08-16
Quidem eos quas in. jace.schuster@waelchiwuckert.name 6 2012-08-16
Qui qui voluptatum reprehenderit assumenda dolorem et rerum sunt. paris_parker@champlin.co.uk 1 2012-08-16
Quas aut omnis tempora voluptates quisquam quia aut. alessandro.hayes@farrell.info 5 2012-08-16
Quaerat eius consequatur itaque id maxime consequatur. kendrick.nader@wyman.us 4 2012-08-16
Perspiciatis sed hic ipsa vitae voluptatem aperiam corrupti qui. alaina.hilpert@roobwunsch.uk 4 2012-08-16
Nisi ut omnis id non commodi maiores. anna@wilkinson.info 6 2012-08-16
Nihil hic magnam id. lucile@marvin.biz 4 2012-08-16
Laudantium cupiditate eaque pariatur aut. zackery.carroll@gibsonshanahan.ca 2 2012-08-16
Itaque aperiam ipsum perferendis ea. maurine@terryrippin.co.uk 6 2012-08-16
Excepturi exercitationem velit itaque. rosie.mayert@hermann.us 8 2012-08-16
Et hic repellat iure. annette@krajcik.name 9 2012-08-16
Doloremque sunt quia sit voluptas aut aut. jeramy@hilpertwehner.com 5 2012-08-16
Dolorem est facere deleniti deserunt veritatis. bertram_larson@braunanderson.name 6 2012-08-16
Dignissimos eius aperiam quo est quam veritatis. donnie_gusikowski@stehr.us 10 2012-08-16
Deleniti vel ut nesciunt dolores voluptatem repellendus dolor. marta_klein@orn.info 2 2012-08-16
Corporis qui consequatur vero nihil aliquid. eldora@kautzerlegros.uk 4 2012-08-16
Aut dolores et voluptatem. donavon_witting@collins.biz 5 2012-08-16
Atque pariatur delectus et ea. rachael@beerschuppe.biz 8 2012-08-16
At distinctio ut consequatur. immanuel@trantow.name 0 2012-08-16
Assumenda nihil accusantium sunt sed illum et saepe. shane@shanahanlueilwitz.info 6 2012-08-16
Assumenda minima deserunt aut distinctio voluptatem vel. lauriane.shanahan@welchwiegand.co.uk 0 2012-08-16
Ad et qui deleniti tempore sit vero. geraldine.spinka@simonis.uk 9 2012-08-16
A mollitia tempora et id eum assumenda. krista.senger@schiller.co.uk 5 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>