Subject: | PATCH: add get_sortable_arrayref |
The attached patch adds get_sortable_arrayref(). It's of interest to
those who want full control over the HTML generated.
Related, it would be nice if the following modules were considered
recommended but not required for this distibution:
Template
Spreadsheet::SimpleExcel
Neither are required to use it successfully and usefully.
Mark
Subject: | sortable_arrayref.diff |
Wed Jun 7 17:55:04 EDT 2006 mark@summersault.com
* add get_sortable_arrayref() to HTML::ReportWriter::PagingAndSorting
diff -rN old-miami/perllib/HTML/ReportWriter/PagingAndSorting.pm new-miami/perllib/HTML/ReportWriter/PagingAndSorting.pm
726a727,778
> =item B<get_sortable_arrayref()>
>
> $cols_aref = $pager->get_sortable_arrayref();
>
> An alternative to C<get_sortable_table_header> for those who want full control over the HTML.
> Produces an arrayref of hashrefs, following this model.
>
> $cols_aref = [
> {
> url => 'http://...', # (may be null of the column is not sortable)
> display => 'Title', # from options given to new()
> is_current => 1, # whether or not this column is the current sort column
> sort_asc => 1, # true if sorted ascending
> }
> ....
> ]
> );
>
> Here's an example of how it might be used with L<HTML::Template>. This example assumes
> that every column is "sortable".
>
> <tr>
> <!-- tmpl_loop columns -->
> <th><a href="<tmpl_var url>"><!-- tmpl_var display --></a>
> <!-- tmpl_if is_current -->
> <!-- tmpl_if sort_asc -->^<!-- tmpl_else -->v<!--/tmpl_if -->
> <!-- /tmpl_if -->
> </th>
> <!-- /tmpl_loop -->
> </tr>
>
> =cut
>
> sub get_sortable_arrayref
> {
> my $self = shift;
>
> my $cols = [];
>
> foreach my $col (@{$self->{'SORTABLE_COLUMNS'}})
> {
> push @$cols, {
> sort_asc => ($self->{'CURRENT_SORT_DIR'} eq 'ASC'),
> url => ($col->{'sortable'} ? $self->get_sort_link($col->{'get'}) : ''),
> display => $col->{'display'},
> is_current => (defined($self->{'CURRENT_SORT_COL'}) && $col->{'get'} eq $self->{'CURRENT_SORT_COL'}),
> }
> }
>
> return $cols;
> }
>