CC: | michael [...] summersault.com |
Subject: | PATCH: add get_sortable_hashref() |
Here's another path to the PagingAndSorting module we've found useful.
Also, I've noticed there has been no response my other patch from a
couple of years ago. If you added me a PAUSE co-maintainer, I could
potentially apply the patches and help with a new release.
The credit for the below routine should go to Michael Hampton, who wrote
it.
Mark
################
=item B<get_sortable_hashref()>
$cols_href = $pager->get_sortable_hashref();
An alternative to C<get_sortable_table_header> and
C<get_sortable_arrayref> for those who
want full control over the HTML. The keys in the hash for each column
are prefixed by
'col_<title>' where <title> is the column's 'get' value.
$cols_href = {
col_<title>_url => 'http://...',
col_<title>_is_current => 1, # whether or not this column is
the current sort column
col_<title>_sort_asc => 1, # true if sorted ascending
};
Here's an example of how it might be used with L<HTML::Template>.
<th>
<a href="<tmpl_var col_full_name_url>">Full Name</a>
<!-- tmpl_if col_full_name_is_current -->
<!-- tmpl_if col_full_name_sort_asc -->^<!-- tmpl_else -->v<!--
/tmpl_if -->
<!-- /tmpl_if -->
</th>
=cut
sub get_sortable_hashref {
my $self = shift;
my $cols = {};
for my $col (@{$self->{'SORTABLE_COLUMNS'}})
{
my $col_get = $col->{'get'};
$cols->{'col_'.$col_get.'_sort_asc'} = ($self-
Show quoted text
>{'CURRENT_SORT_DIR'} eq 'ASC');
$cols->{'col_'.$col_get.'_url'} = ($col->{'sortable'} ?
$self->get_sort_link($col_get) : '');
$cols->{'col_'.$col_get.'_is_current'} = (defined($self-
Show quoted text>{'CURRENT_SORT_COL'}) && $col_get eq $self->{'CURRENT_SORT_COL'});
}
return $cols;
}