[ANN] Table Helper for Ruby on Rails

B

Bauduin Raphael

Hi all,

I have put the initial release (0.1) of a table helper for Ruby on Rails
at http://tablehelper.rubyforge.org , with an demo page at
http://www.raphinou.com/rails/table_demo/index .
This component is designed to display data from an Array into an HTML table.
It is possible to display an array data in a simple html table, but also
to use more advanced features like:
- displaying certain fields of the table as links (links that can be
built thanks to the data from other fields in the row, like adding
parameters to the URL)
- displaying column headers to sort the displayed data
- manipulate the data before it gets displayed (useful for translations eg)
- styling each part of the table with CSS
- display navigation links when the number of rows is too big to be
displayed on one page
- give an id to the table and each row (for CSS or javascript
manipulation eg)


The simplest example (also available at the demo page) is like this:
simple_array = [ [ 1, "Ruby", "http://www.ruby-lang.org"],
[ 2, "Python", "http://www.python.org"],
[ 3, "Java", "http://www.java.sun.com"],
[ 4, "Perl", "http://www.perl.org"],
[ 5, "lua", "http://www.lua.org"]
]

#controller
@e = { "array" => simple_array }
#view
<%= table(@e1, "display" => :default) %>

All further parameters are passed to the helper by instantiating the
TableFields class.

To give an id to the table, we can do this:
#controller
fields = TableFields.new:)table_id => "example")
@e = { "array" => simple_array , "fields" => fields}


We can set the column names:
fields.field_names = [ "id", "name", "homepage"]

Links are defined thanks to the LinkSpec class. Eg:

ror_link_spec = LinkSpec.new
ror_link_spec.href = "http://www.rubyonrails.org"

fields.add_link("column_name", ror_link_spec)

A link built with the data in the array is also simple, but I'll let you
discover this and the other features at the demo page. Feedback and
comments are welcome.

Raph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top