El Grillo
 
 

One

The Controller:

   def one
      @grid = Grillo.new
      @grid.add_column('last_name')
      @grid.add_column('name')
      @grid.add_column('login')
      @grid.add_column('password')
      @grid.fill_from_database(DemoTable)
   end
     	

The View:

   	<%= render_grillo @grid %>
	

El grillo in its most simple encarnation. It will display the data of the DemoTable table, showing some columns.

 
 

Two

The Controller:

   def two
      @grid = Grillo.new
      @grid.add_column('id_externo',     :align=>:center)
      @grid.add_column('hora_recep_bo',  :header=>'Hora recepcion', :type=>:short_date)
      @grid.add_column('total_nota',     :type=>:currency)
      @grid.add_column('terminal',       :type=>:number)
      @grid.add_column('movil',          :type=>:phone)
      @grid.add_column('mensaje_respuesta')
      @grid.add_column('id_tx',          :header=>'Detalle Nota', :type=>:link_to,
                                         :options=>{:label=>'ver', :action=>:one})
      @grid.fill_from_database(HeaderNotaVenta, :limit=>50, :order=>'hora_recep_bo desc')
   end

     	

The View:

   	<%= render_grillo @grid %>
	

This example shows how to align and format columns. The last column, is an (image) link to another action. It will how the first 50 rows. A default order is specified.

 
 

Three

The Controller:

   def three
        @grid = Grillo.new( :title=>'Ranking de llamadas: internas->externas (desde hace 2 dias)' )
        @grid.add_column("clid",                :header=>'El que llamo')
        @grid.add_column("veces",               :type=>:number, :sql_select=>" lpad(count(*),2,'0') ")
        @grid.fill_from_database(Cdr,
                :conditions=>"clid!='' AND disposition='ANSWERED' AND clid like '%<%' AND calldate>'#{2.days.ago}' ",
                :group=>'clid',
                :order=>'veces desc',
                :limit=>30
        )
   end


     	

The View:

   	<%= render_grillo @grid %>
	

This example shows how to work with specific database querys. Group by. Also, it will read the sql_parameter and execute " SELECT clid, lpad(count(*),2,'0') AS veces FROM ...." . It sets the title of the gillo.

 
 

Four

The Controller:

   def four
        @grid = Grillo.new :title=>'Productos'
        @grid.add_column("productos.codigo",            :header=>'Codigo', :type=>:number)
        @grid.add_column("productos.descripcion",       :header=>'Descripcion', :type=>:string)
        @grid.add_column("peso_kg",                     :header=>'Peso', :type=>:number, :sql_select=>" ltrim(peso_kg,'0') ")
        @grid.add_column("familias.descripcion",        :header=>'Familia', :type =>:string)
        @grid.add_column("productos.familia_id",        :header=>'Ver familia', :type =>:image_link_to,
                                                                                :options=>{:image=>'next.png'})
        @grid.fill_from_database(Producto, :joins=>"INNER JOIN familias ON familias.id=productos.familia_id", :limit=>50)
   end


  	

The View:

   	<%= render_grillo @grid %>
	

This example shows how to work with JOINS

 
 

Five

The Controller:

   def five
        @grid  = Grillo.new(
                :pages=>pages_options(:pages_label=>'P\xc3\xa1gina %s de %s'),
                :search=>search_options,
                :order=>order_options,
                :title=>"Registro de Llamadas"
        )
        @grid .add_column("calldate",       :header=>'Fecha', :type=>:short_date, :orderable=>true)
        @grid .add_column("clid",               :header=>'Origen', :type=>:phone, :searchable=>true, :orderable=>true)
        @grid .add_column("dst",                :header=>'Destino', :type=>:phone, :searchable=>true)
        @grid .add_column("duration",           :header=>'Duración', :searchable=>true,
                                                :format=>'%s [min]', :type=>:number, :sql_select=>" duration/60 ")
        @grid .add_column("dstchannel", :header=>'Canal')
        @grid .add_column("disposition",        :header=>'Estado', :searchable=>true)
        @grid .add_column("lastapp",    :header=>'Comando')
        @grid.fill_from_database(Cdr, :conditions=>"src!='' and duration>'25'")
   end

  	

The View:

   	<%= render_grillo @grid %>
	

The usage of some grillo properties, enabling ordering, search and pagination. The label of the pages is getting changed from the default value. Produces de following output:

 
 

Six

The Controller:

   def six
        @grid = Grillo.new( :title=>'Datos de un rectangulo' )
        @grid.add_column("lado1",       :sql_select => ' CAST( RANDOM()*10 as INT) ',
                                        :type => :number, :format=>' %s cm' )
        @grid.add_column("lado2",       :sql_select => ' CAST( RANDOM()*10 as INT)  ',
                                        :type => :number, :format=>' %s cm' )
        @grid.add_column("perimetro",   :value => " (:lado1: + :lado2:) *2 ",
                                        :type => :number, :format=>' %s cm' )
        @grid.add_column("area",        :value => " :lado1: * :lado2:",
                                        :type => :number, :format=>' %s cm2')
        @grid.fill_from_database(Producto, :limit=>100)
   end


  	

The View:

   	<%= render_grillo @grid %>
	

Shows how to make operations with values from other columns. Perimeter = 2* (side1 + side2). Area = side1 * side2. All is getting processed by the ruby interpreter.