What is
El Grillo?
El Grillo is a Ruby on Rails plugin that helps you show tabular data in a simple way. Main features are:
- Pagination
- Search
- Order by Columns
- ActiveRecord/SQL support
- PDF and Microsoft Excel 2006 export
- Cell formatting depending of the data type
- Execution of Ruby code, and do inter-cell operations
- Actions
El Grillo focus in standard html so any html browser will be able to display the data. No fancy AJAX.
El Grillo is a work in progress, at a early development stage, so use it carefully. We strongly suggest you to download the source and help El Grillo grow.
El Grillo uses Ruby FPDF (for PDF export) and Rolando Abarca Millán's scio_excel.rb (for Excel 2006 export). Be sure to install them for the full El Grillo experience!
Installation
El grillo can be used as a RoR plugin. This means you can download it in your vendor/plugins directory. Additionally, you can copy the default style and images to your main project:
- Create your project:
- Point to the database you want to use:
- Edit your_project_name/config/database.yml
- Copy el grillo plugin:
-
cd your_project_name/vendor/plugins
-
svn co http://el-grillo.rubyforge.org/svn/trunk/vendor/plugins/grillo
- Copy default style and images:
- cd ../../public
- rm -r images stylesheets
- svn export http://el-grillo.rubyforge.org/svn/trunk/public/images
- svn export http://el-grillo.rubyforge.org/svn/trunk/public/stylesheets
- cd ..
- Write, and start your project!
You can get the full sources from the
project repository at
RubyForge.
Example
The Controller:
def example
@grid = Grillo.new(
:order=>order_options,
:search=>search_options,
:pages=>pages_options,
:export=>export_options,
:title=>"Calls from the outside"
)
@grid.add_column("calldate", :header=>'Date', :orderable=>true, :type=>:short_date)
@grid.add_column("clid", :header=>'Source', :type=>:phone, :searchable=>true, :orderable=>true)
@grid.add_column("dst", :header=>'Destiny', :type=>:phone, :orderable=>true)
@grid.add_column("duration", :header=>'Duration', :orderable=>true, :format=>'%s [min]', :type=>:number, :sql_select=>" duration/60 ")
@grid.add_column("dstchannel", :header=>'Channel')
@grid.add_column("disposition",:header=>'State', :orderable=>true)
@grid.add_column("lastapp", :header=>'Command')
@grid.fill_from_database(Cdr, :conditions=>"src!='' and duration>'25'")
end
The View:
<%= render_grillo @grid %>
Produces the following output:
Just download the sample proyect and try it!
Docs
The main component of El Grillo is the column, that's because a data grid is composed by columns. There's
four main groups of options for the columns:
| Option | Type | Description |
| Format Options |
| :width | Numeric | Width of the column. |
| :position | Numeric | Position of the column. |
| :header | String | Title for the column. |
| :align | :center, :left, :right | Speaks for itself. |
| Data Format |
| :type | :string | Format the data as String (aligned to the left). |
| :type | :number | Format the data as Numeric (aligned to the right). |
| :type | :percent | Number ended with a '%' symbol. |
| :type | :currency | Number started with a '$' symbol. |
| :type | :phone | Number formatted as a phone. |
| :type | :link_to | Creates a link on the cell. |
| :type | :link_image_to | Creates an image link on the cell. |
| :type | :hidden | Creates a hidden column (for :type => :value). |
| :type | :hide | Capture de data, but do not display it. Usefull for reference it from another column |
| :options | Hash | Options for some cell types (like :link_to and :image_link_to). |
| :format | String | Overrides the default format, i.e "%s [min]". |
| Data Options |
| :code | String | Executes a code. Accepts Ruby primitives. |
| :sql_select | String | Overwrite the column portion of the 'SELECT' so you can execute database commands directly. |
| :value | String | Execute operation between columns, referenced by its ids. |
| Column Options |
| :searchable | Boolean | Enables search on this column. |
| :orderable | Boolean | Enables order on this column. |
The other part of a data grid is the data source. The method 'fill_from_database' accepts two parameters, the Object (a model) and a hash of
parameters, same as the 'find' method.
Check this
examples that shows El Grillo capabilities.
Credits and
License
El Grillo is developed by
Marcelo Soto Montes and Phillip Neumann. Sponsored and supported by TransTel Ltda Chile, Servicios y Soluciones de Negocios Móviles.
The program is licensed under the MIT License. Use at your own risk