HTML table styling

29 views
Skip to first unread message

map7

unread,
Mar 15, 2010, 11:31:08 PM3/15/10
to Ruby Reports
I've just started using ruport 1.6.3 and I would like to have
different widths for each of my columns in the html output of my
table.

Is there any way to individually set the widths? or set a style for a
<td> tag so I can apply a style sheet to it?

Andrew France

unread,
Mar 16, 2010, 1:30:19 AM3/16/10
to ruby-r...@googlegroups.com

The HTML formatter is very basic, simply concatenating the tag strings
with the values. The original way to adjust output is to override the
build_* method, such as build_row. Since I don't like mixing formatting
and code I tend to use ERB or HAML for output.

Hope that helps,
Andrew

map7

unread,
Mar 16, 2010, 6:34:27 PM3/16/10
to Ruby Reports
Do you override the build_* methods in the subclass or
Ruport::Formatter::HTML? As I just tried overriding
build_table_header and it didn't override it. Here is my override:

class HTML < Ruport::Formatter::HTML
renders :html, :for => CarReport

def build_table_header
output << "\t\t<tr>\n\t\t\t"

@i = 0
data.column_names.each do |col|
output << "<th class='ruport_th#{@i}'></th>"
@i += 1
end
output << "\n\t\t</tr>\n"
end

def build_car_report
output << textile("h1. Car Report")
output << data.to_html(:style => :justified)
end
end

map7

unread,
Mar 16, 2010, 7:19:12 PM3/16/10
to Ruby Reports
I also tried setting my renders like mentioned in other post in this
mailing list:
renders :html, :for => [CarReport, Ruport::Controller::Table]

Still it doesn't pick up my build_table_header method.

Andrew France

unread,
Mar 16, 2010, 8:34:17 PM3/16/10
to ruby-r...@googlegroups.com
Hi Mike,

I'm afraid I'm really busy at the moment to be of much help. You seem to
be doing the right thing so I'm not sure why it isn't working. The
renderer is perhaps a bit dumb when picking up Formatters and selects
the first in its list (formats method IIRC).

For the moment you could just render the table manually in the formatter.

I'll try to have a proper look tonight. None of my reports in any of my
projects use the HTML table formatter!

Best regards,
Andrew

map7

unread,
Mar 16, 2010, 11:31:58 PM3/16/10
to Ruby Reports
Got it working I just had to add this:

renders :html, :for => [CarReport, Ruport::Controller::Table]
Reply all
Reply to author
Forward
0 new messages