Project

gitter

0.0
No commit activity in last 3 years
No release in over 3 years
To be used within Rails applications. Helps you to define searches with filters and facets and data tables with sortable columns and filters.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

gitter

Ruby library for Rails which enables you to create data grids, i.e table like data with customizable

  • Filters
  • Sortables columns
  • Faceted search
  • Localization

Data Grids

In order to define a grid you need to provide:

  • a scope which returns the objects for the grid's rows
  • filters that will be used to filter the rows
  • columns to be displayed

Example:

class ArticleGrid << Gitter::Grid

  ### First define the source for your data
  # helpers are accessible by #h
  scope do
    Article.where(:owner => h.current_user)
  end

  ### Then you may define filters

  # filter by attribute
  filter :name

  # filter by multiple columns: filters by :name OR :description
  filter :search, :columns => [:name, :description]

  # filter by named scope
  filter :topsellers, :scope => :topsellers

  # customized filter
  filter :on_stock do |scope|
    scope.where('stock > 0')
  end

  filter :out_of_stock do |scope|
    scope.where(:stock => 0)
  end

  # select from given filters
  filter :availability, :select => [:on_stock, :out_of_stock]

  # add to facets
  filter :category, :facet => true

  # select among named scopes
  filter :price_range, :scopes => [:niceprice, :regular]

  # you can provide 'search' like attributes
  filter :search, :ignore_case => true, :exact => false

  # The former can be abbreviated by
  search :search

  ### Define your data grid

  # show an attribute
  column :article_no

  # provide a hardcoded header (i18n support also available)
  column :description, :header => 'Details'

  # make the column sortable
  column :name, :sort => true

  # Customize your data cell
  # Access your model through variable 'model'
  column :price, :sort => true do
    "#{model.price/100.floor},#{model.price%100} USD"
  end

  # helpers are accessible via #h
  column :details, :header => false do
    h.link_to 'details', h.edit_article_path(self)
  end

end

More about filters

More about columns

#Rendering your grid

For the most common use case -- your controller -- you simply do:

def index
  @grid = ArticleGrid.new(self)
end

Render you grid:

%table
  %tr
    - @grid.headers.each do |header|
      %th = header

  - @grid.rows.each do |row|
    %tr
      - row.each do |cell|
        %th = cell

More about grids

Facets

Render your facets:

%ul
  - @grid.facets do |facet|
    %li
      = facet.label
      %ul
        - facet.data.each do |data|
          = data.value
          = link_to "(#{data.count})", data.link

More about facets

Breadcrumbs

Render your breadcrumbs:

@grid.render_breadcrumbs

More about inputs

ORM Support

  • ActiveRecord
  • others: Help or suggestions are welcome

Credits

API inspired by datagrid

License

Gitter is released under the MIT license

Copyright © 2013 Thomas Sonntag