I was wondering if anybody crafted a "Datagrid" helper that would receive a array of object, column definitions and other stuff and would render a nice table. I built one, that works well, but it is ugly as hell. Here is an example of usage: <% dg = DataGrid.new(@contexts, self) dg.row_count = { :label => "context" } dg.actions << { :eval => "link_to(''[Add New Context]'', :action => ''new'')" } dg.actions << { :eval => "link_to(''[Clear All Contexts]'', :action => ''clear'')" } dg.columns << { :label => "Name", :eval => "item.name" } dg.columns << { :label => "Type", :eval => "item.type.to_s" } dg.columns << { :eval => "link_to(''[Edit]'', :action => ''edit'', :id => item.id)" } dg.columns << { :eval => "link_to(''[Delete]'', :action => ''delete'', :id => item.id)" } %> <%= dg.render %> It renders a nicely alternating color table, with 4 columns (2 for data and 2 for row actions: edit and delete), a row count and 2 global actions. Anybody has come up with something better? Regards, Demetrius
Check this out: http://tablehelper.rubyforge.org/ Demetrius Nunes wrote:> I was wondering if anybody crafted a "Datagrid" helper that would > receive a array of object, column definitions and other stuff and would > render a nice table. > > I built one, that works well, but it is ugly as hell. Here is an example > of usage: > > <% > dg = DataGrid.new(@contexts, self) > dg.row_count = { :label => "context" } > dg.actions << { :eval => "link_to(''[Add New Context]'', :action => ''new'')" } > dg.actions << { :eval => "link_to(''[Clear All Contexts]'', :action => > ''clear'')" } > dg.columns << { :label => "Name", :eval => "item.name" } > dg.columns << { :label => "Type", :eval => "item.type.to_s" } > dg.columns << { :eval => "link_to(''[Edit]'', :action => ''edit'', :id => > item.id)" } > dg.columns << { :eval => "link_to(''[Delete]'', :action => ''delete'', :id > => item.id)" } > %> > <%= dg.render %> > > It renders a nicely alternating color table, with 4 columns (2 for data > and 2 for row actions: edit and delete), a row count and 2 global actions. > > Anybody has come up with something better? > > Regards, > Demetrius > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanks Luis, I''ll try to use that in future projects. Are there any intentions in the Rails community to build a complete set of HTML controls a la ASP.NET ? Luis G. Gómez wrote:> Check this out: http://tablehelper.rubyforge.org/ > > Demetrius Nunes wrote: > >> I was wondering if anybody crafted a "Datagrid" helper that would >> receive a array of object, column definitions and other stuff and >> would render a nice table. >> >> I built one, that works well, but it is ugly as hell. Here is an >> example of usage: >> >> <% >> dg = DataGrid.new(@contexts, self) >> dg.row_count = { :label => "context" } >> dg.actions << { :eval => "link_to(''[Add New Context]'', :action => >> ''new'')" } >> dg.actions << { :eval => "link_to(''[Clear All Contexts]'', :action => >> ''clear'')" } >> dg.columns << { :label => "Name", :eval => "item.name" } >> dg.columns << { :label => "Type", :eval => "item.type.to_s" } >> dg.columns << { :eval => "link_to(''[Edit]'', :action => ''edit'', :id => >> item.id)" } >> dg.columns << { :eval => "link_to(''[Delete]'', :action => ''delete'', >> :id => item.id)" } >> %> >> <%= dg.render %> >> >> It renders a nicely alternating color table, with 4 columns (2 for >> data and 2 for row actions: edit and delete), a row count and 2 >> global actions. >> >> Anybody has come up with something better? >> >> Regards, >> Demetrius >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >