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
Eaque quia exercitationem vel. bertha_stamm@cruickshank.info 10 2012-08-16
Veniam et sit dolorem. norbert@funk.us 10 2012-08-16
Eum corporis ut sint omnis dignissimos ullam ad. enrique@littlegleichner.ca 10 2012-08-16
Perspiciatis delectus quas eligendi autem sint. idella_feeney@goodwinschmitt.uk 9 2012-08-16
Asperiores aut ea iste ipsam est sapiente. freeda@hermiston.com 9 2012-08-16
Blanditiis corporis delectus quia accusamus. layne@creminhauck.co.uk 8 2012-08-16
Fugiat voluptates atque ad dolores sit et exercitationem. garrett@powlowski.co.uk 8 2012-08-16
Qui eum odio ab qui. lolita@dare.uk 7 2012-08-16
Magni eius consequatur a. brant_mccullough@crist.us 7 2012-08-16
Facere reiciendis et vel autem. jalyn@oconnell.us 6 2012-08-16
Provident unde nesciunt consequatur maiores expedita in. savannah@hills.co.uk 6 2012-08-16
Aut molestiae voluptatem consequatur nostrum totam saepe. kaleb_champlin@dach.info 6 2012-08-16
Ullam libero non aspernatur adipisci. alia.mayer@grimes.info 5 2012-08-16
At reiciendis qui aliquam dolorem sapiente esse corporis tempore. amina@brownmertz.uk 4 2012-08-16
Aut voluptatum porro nobis ut rerum similique hic. alexander@sanford.uk 3 2012-08-16
Rerum in quidem beatae deleniti unde id. shannon.quigley@schulist.info 1 2012-08-16
Itaque velit quis ut aperiam. syble@bruen.co.uk 1 2012-08-16
Dolores tempore consectetur quis laborum. madelynn@hills.ca 0 2012-08-16
Unde quam eum delectus voluptate qui molestiae ea. gia_kuvalis@kerluke.biz 0 2012-08-16
Dignissimos eius aperiam quo est quam veritatis. donnie_gusikowski@stehr.us 10 2012-08-16
Et hic repellat iure. annette@krajcik.name 9 2012-08-16
Ut dolor non debitis eum. tessie@koch.co.uk 9 2012-08-16
Ad et qui deleniti tempore sit vero. geraldine.spinka@simonis.uk 9 2012-08-16
Atque pariatur delectus et ea. rachael@beerschuppe.biz 8 2012-08-16
Excepturi exercitationem velit itaque. rosie.mayert@hermann.us 8 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>