HTML-QuickTable
view release on metacpan or search on metacpan
my $dbh = DBI->connect( ... );
my $all_arrayref = $dbh->selectall_arrayref("select * from billing");
print $qt->render($all_arrayref);
With "header => 1", you will get a brief "CGI" header as well as some
basic "HTML" to prettify things. As such, the above will print out all
the rows that your query selected in an "HTML" table.
FUNCTIONS
new(opt => val, opt => val)
The "new()" function takes a list of options and returns a $qt object,
which can then be used to "render()" different data. The "new()"
function has a flexible options-parsing mechanism that allows you to
specify settings to pretty much any element of the table.
Options include:
header => 1 | 0
If set to 1, a basic "CGI" header and leading "HTML" is printed out.
Useful if you're really looking for quick and dirty. Defaults to 0.
htmlize => 1 | 0
If set to 1, then all values will be run through a simple filter
that creates links for things that look like email addresses or
websites. Also, "*word*" will be changed to "<b>word</b>", and
"_word_" will be changed to "<i>word</i>".
labels => 1 | 0 | LTRB
If set to 1, then the first row of the data is used as the labels of
the data columns, and is placed in "<th>" tags. For example, if we
assume our above data structure, and said:
my $qt = HTML::QuickTable->new(... labels => 1);
unshift @data, ['User', 'Name', 'Ext', 'Email'];
print $qt->render(\@data);
You would get something like this:
<table>
<tr><th>User</th><th>Name</th><th>Ext</th><th>Email</th></tr>
<tr><td>nwiger</td><td>Nathan Wiger</td><td>x43264</td><td>nate@wiger.org</td></tr>
<tr><td>jbobson</td><td>Jim Bobson</td><td>x92811</td><td>jim@bobson.com</td></tr>
</table>
Since the labels are placed in "<th>" tags, you can then use the
extra "HTML" options described below to alter the way that the
labels look.
You can also set this to a string that includes the characters L, T,
R, and B, to specify that "<th>" tags should be created for the
Left, Top, Right, and Bottom rows and columns. So for example:
labels => 'LT'
Would alter the table so that both the first row AND first column
had "<th>" instead of "<td>" elements. This is useful for creating
tables that have two axes, such as calendars.
null => $string
If set, then null (undef) fields will be set to that string instead.
This is useful if pulling a bunch of records out of a database and
not wanting to get blank table spaces everywhere there's a null
field. For example:
my $qt = HTML::QuickTable->new(null => '-');
my $all_arrayref = $sth->fetchall_arrayref;
print $qt->render($all_arrayref);
By default null table elements are left blank.
nulltags => \%hash
In addition to just changing the string used to represent null data,
you may want to change the look of it as well. These tags will
become attributes to the "<td>" element holding the null field. So,
settings like this:
null => 'N/A',
nulltags => {bgcolor => 'gray'},
Would result in an element like the following for null fields:
<td bgcolor="gray">N/A<td>
Make sense?
stylesheet => 1 | '/path/to/style.css'
If set, then any font settings are ignored and instead all table
elements are wrapped with a "class=" attribute. The class name is
whatever "styleclass" is set to (see below). See also the "useid"
option to generate "id" tags in an intelligent way.
styleclass => $string | \@array
This used as a style class to use if the above setting is used. If
set to a string, it is passed directly to the "class" tag. If set to
an arrayref, then those styles are alternated between on a
row-by-row ("tr") basis. For example:
styleclass => [qw(one two)]
Would yield "XHTML" similar to:
<table class="one">
<tr class="one">
<td class="one">a</td>
<td class="one">b</td>
<td class="one">c</td>
<td class="one">d</td>
</tr>
<tr class="two">
<td class="two">e</td>
<td class="two">f</td>
<td class="two">g</td>
<td class="two">h</td>
</tr>
</table>
Notice that the table gets the style of the first array element.
( run in 1.050 second using v1.01-cache-2.11-cpan-e1769b4cff6 )