Adding CSS onto specific rows of a HTML result table

32 views
Skip to first unread message

thehunfromoz

unread,
Feb 5, 2009, 7:32:01 PM2/5/09
to Ruby Reports
Hi Folks,

I'm a little stumped with this. I've got a report where I wanted to
hide various rows, using some CSS and javascript. To achieve that, I
figured simply modify the <tr> tag, attaching a
class="hide_this_row_when_clicked" to it, and then using some simple
javascript go and toggle the rows visibility, as required. So far, so
good.

My problem is, I don't know if there's an easy way to get at the <tr>
elements. Yes, I can use a ":transforms=>lambda{}" block for columns
of the row ... but how do I get access to the <tr> element itself, to
inject the 'class=' snippet ?.

I thought about using Ruport::Formatter::HTML ... but I'm still
grappling with ruports basics, and was wondering if there's an easier
way ?. Not saying Ruport::Formatter::HTML isn't easy, just doesn't
look that way when diving in at the deep end.

Any hints would be greatly appreciated :0)

Thanks.

George

unread,
Feb 27, 2009, 1:17:03 PM2/27/09
to Ruby Reports
I had a similar need, which was to style the table by adding borders
(which I couldn't figure out how to do using CSS alone), set up even /
odd shading on the rows, and add special colors to the header row.

What I did to accomplish this is to monkey patch the built-in
Ruport::Formatter::HTML and overwrite the methods build_table_header
and build_row, and render_justified_grouping to add the necessary
style classes to <table> and <tr>.

It would be a nice-to-have in Ruport to add properties to the HTML
formatter that would make easy to adjust the table parameters and set
style classes for the tags.

George Feil
Principal Engineer
New Relic

Gregory Brown

unread,
Feb 27, 2009, 1:19:14 PM2/27/09
to ruby-r...@googlegroups.com
On Fri, Feb 27, 2009 at 1:17 PM, George <g...@star-d.dj> wrote:
>
> I had a similar need, which was to style the table by adding borders
> (which I couldn't figure out how to do using CSS alone), set up even /
> odd shading on the rows, and add special colors to the header row.
>
> What I did to accomplish this is to monkey patch the built-in
> Ruport::Formatter::HTML and overwrite the methods build_table_header
> and build_row, and render_justified_grouping to add the necessary
> style classes to <table> and <tr>.

Why monkey patch it when you could subclass it? That's the whole
point of the formatters, except for the most basic needs.

> It would be a nice-to-have in Ruport to add properties to the HTML
> formatter that would make easy to adjust the table parameters and set
> style classes for the tags.

How would you like this to work, specifically? If I can see some
pseudo code for what it would look like, maybe I can implement it for
Ruport 2.

-greg

George Feil

unread,
Feb 27, 2009, 1:35:39 PM2/27/09
to ruby-r...@googlegroups.com
I was going to subclass them, but was getting hung up on how to hook
my formatter into the Ruport::Data::Table instance generated through
acts_as_reportable. I couldn't find an example of this in the book or
the documentation.

George

Gregory Brown

unread,
Feb 27, 2009, 1:43:24 PM2/27/09
to ruby-r...@googlegroups.com
On Fri, Feb 27, 2009 at 1:35 PM, George Feil <g...@star-d.dj> wrote:
>
> I was going to subclass them, but was getting hung up on how to hook
> my formatter into the Ruport::Data::Table instance generated through
> acts_as_reportable. I couldn't find an example of this in the book or
> the documentation.

So long as you don't mind making the change system wide:

render :html, :for => [Ruport::Controller::Grouping, Ruport::Controller::Group,
Ruport::Controller::Table,
Ruport::Controller::Row ]

should do the trick in your formatter subclass. I'm aware this sort
of hack leaves something to be desired. The Fatty based formatting
engine will be much more pleasant to work with.

-greg

Reply all
Reply to author
Forward
0 new messages