datagrid 0,0,3,0,0,0 rspec travis-ci ruby Rubygems

Gem to create tables grids with sortable columns and filters


Build Status

Ruby library that helps you to build and represent table-like data with:

  • Customizable filtering
  • Columns
  • Sort order
  • Localization
  • Export to CSV

ORM Support

  • ActiveRecord
  • Mongoid
  • MongoMapper
  • Sequel
  • Array (slow but possible)

Create an issue if you want more.


  • Ruby >= 2.0
  • Rails >= 3.2

Live Demo

Datagrid DEMO application is available live! Demo source code.


In order to create a grid:

class UsersGrid

  include Datagrid

  scope do

  filter(:category, :enum, select: ["first", "second"])
  filter(:disabled, :xboolean)
  filter(:group_id, :integer, multiple: true)
  filter(:logins_count, :integer, range: true)
  filter(:group_name, :string, header: "Group") do |value|
    self.joins(:group).where(:groups => {:name => value})

  column(:group, order: -> { joins(:group).order(groups: :name) }) do |user|
  column(:active, header: "Activated") do |user|


Basic grid api:

report =
  :group_id => [1,2], 
  :logins_count => [1, nil],
  :category => "first",
  :order => :group,
  :descending => true

report.assets # => Array of User instances:
              # SELECT * FROM users WHERE users.group_id in (1,2) AND users.logins_count >= 1 AND users.category = 'first' ORDER BY DESC

report.header # => ["Name", "Group", "Activated"]
report.rows   # => [
              #      ["Steve", "Spammers", false],
              #      [ "John", "Spoilers", false],
              #      ["Berry", "Good people", true]
              #    ]   # => [ header, *rows]

report.to_csv # => Yes, it is

Grid DSL

In order to create a report, you need to define:

  • scope of objects to look through
  • filters that will be used to filter data
  • columns that should be displayed and sortable (if possible)


Default scope of objects to filter and display. In common case it is ActiveRecord::Base (or any other supported ORM) subclass with some generic scopes like:

scope do

More about scope


Each filter definition consists of:

  • name of the filter
  • type that will be used for value typecast
  • conditions block that applies to defined scope
  • additional options

Datagrid supports different type of filters including:

  • text
  • integer
  • float
  • date
  • datetime
  • boolean
  • xboolean - the select of “yes”, “no” and any
  • enum - selection of the given values
  • string
  • dynamic - build dynamic SQL condition

More about filters


Each column is represented by name and code block to calculate the value.

column(:activated, :header => "Active", :order => "activated", :after => :name) do

Some formatting options are also available. Each column is sortable.

More about columns

Front end

Using Generator

Datagrid has a builtin generator:

rails g datagrid:scaffold skills

That gives you some code to play with out of the box:

create  app/grids/skills_grid.rb
create  app/controllers/skills_controller.rb
create  app/views/skills/index.html.erb
route  resources :skills
insert  app/assets/stylesheet/application.css

Customize Built-in partials

In order to get a control on datagrid built-in partials run:

rake datagrid:copy_partials

Advanced frontend

All advanced frontend things are described in:

Frontend section on wiki

Questions & Issues

If you have a question of any kind, just make an issue and describe your problem in details.


Like datagrid?

Follow the repository on GitHub.

Read author blog.

Related Repositories



A carefully crafted DataGrid for React ...



A carefully crafted DataGrid for React ...



Gem to create tables grids with sortable columns and filters ...



Symfony2 Datagrid Bundle ...



The Angular Datagrid. Highly optimized AngularJS datagrid, works great on mobile. Easily modify and add your own behavior with addons! Now your ng-repeat doesn't have to bog down your app when you have lots of data to show. ...

Top Contributors

bogdan holderbaum mipearson barendt ka8725 olejrosendahl nicolai86 swlkr jasonpaluck francois hamin jswanner dmitry-ilyashevich jjbohn shanlalit lucasefe heythisisnate yrgoldteeth lazing artofhuman adamjonas benolee leomao10 markedmondson


-   v1.4.4 zip tar
-   v1.4.3 zip tar
-   v1.4.2 zip tar
-   v1.4.1 zip tar
-   v1.4.0 zip tar
-   v1.3.9 zip tar
-   v1.3.7 zip tar
-   v1.3.6 zip tar
-   v1.3.5 zip tar
-   v1.3.4 zip tar
-   v1.3.3 zip tar
-   v1.3.2 zip tar
-   v1.3.1 zip tar
-   v1.3.0 zip tar
-   v1.2.3 zip tar
-   v1.2.2 zip tar
-   v1.2.1 zip tar
-   v1.2.0 zip tar
-   v1.1.2 zip tar
-   v1.1.1 zip tar
-   v1.1.0 zip tar
-   v1.0.5 zip tar
-   v1.0.4 zip tar
-   v1.0.3 zip tar
-   v1.0.2 zip tar
-   v1.0.1 zip tar
-   v1.0.0 zip tar
-   v0.9.3 zip tar
-   v0.9.2 zip tar
-   v0.9.1 zip tar